cache

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 9 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobCache

type BlobCache interface {
	// Add returns a writer to add contents to cache
	Add(key string, opts ...Option) (Writer, error)

	// Get returns a reader to read the specified contents
	// from cache
	Get(key string, opts ...Option) (Reader, error)

	// Close closes the cache
	Close() error
}

BlobCache represents a cache for bytes data

func NewDirectoryCache

func NewDirectoryCache(directory string, config DirectoryCacheConfig) (BlobCache, error)

func NewMemoryCache

func NewMemoryCache() BlobCache

type DirectoryCacheConfig

type DirectoryCacheConfig struct {

	// Number of entries of LRU cache (default: 10).
	// This won't be used when DataCache is specified.
	MaxLRUCacheEntry int

	// Number of file descriptors to cache (default: 10).
	// This won't be used when FdCache is specified.
	MaxCacheFds int

	// On Add, wait until the data is fully written to the cache directory.
	SyncAdd bool

	// DataCache is an on-memory cache of the data.
	// OnEvicted will be overridden and replaced for internal use.
	DataCache *lrucache.Cache

	// FdCache is a cache for opened file descriptors.
	// OnEvicted will be overridden and replaced for internal use.
	FdCache *lrucache.Cache

	// BufPool will be used for pooling bytes.Buffer.
	BufPool *sync.Pool

	// Direct forcefully enables direct mode for all operation in cache.
	// Thus operation won't use on-memory caches.
	Direct bool
}

type MemoryCache

type MemoryCache struct {
	Membuf map[string]*bytes.Buffer
	// contains filtered or unexported fields
}

MemoryCache is a cache implementation which backend is a memory.

func (*MemoryCache) Add

func (mc *MemoryCache) Add(key string, opts ...Option) (Writer, error)

func (*MemoryCache) Close

func (mc *MemoryCache) Close() error

func (*MemoryCache) Get

func (mc *MemoryCache) Get(key string, opts ...Option) (Reader, error)

type Option

type Option func(o *cacheOpt) *cacheOpt

func Direct

func Direct() Option

Direct option lets FetchAt and Add methods not to use on-memory caches. When you know that the targeting value won't be used immediately, you can prevent the limited space of on-memory caches from being polluted by these unimportant values.

type Reader

type Reader interface {
	io.ReaderAt
	Close() error
}

Reader provides the data cached.

type Writer

type Writer interface {
	io.WriteCloser
	Commit() error
	Abort() error
}

Writer enables the client to cache byte data. Commit() must be called after data is fully written to Write(). To abort the written data, Abort() must be called.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL