Documentation ¶
Overview ¶
Package cache implements the interface to interact with a cache. There are 4 implemented caches: freecache, lru, passthrough, and simple cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FakeCache ¶
type FakeCache struct { FixedValue []byte // contains filtered or unexported fields }
func NewFakeCache ¶
type FakeKVPairReader ¶
type FakeKVPairReader struct { Remaining uint64 // contains filtered or unexported fields }
func NewFakeKVPairReader ¶
func NewFakeKVPairReader(numElems uint64) *FakeKVPairReader
func (*FakeKVPairReader) Close ¶
func (r *FakeKVPairReader) Close()
type FreeCache ¶
type FreeCache struct {
// contains filtered or unexported fields
}
func NewFreeCache ¶
NewFreeCache funtion returns a new cache with a parametrized size.
func (FreeCache) Equal ¶
Equal function checks if every element from current cache (C) exists in the cache to compare (O). It does not check that every element from (O) exists in current cache (C).
func (*FreeCache) Fill ¶
func (c *FreeCache) Fill(r storage.KVPairReader) (err error)
Fill function inserts a bulk of key/value elements into the cache.
func (FreeCache) Get ¶
Get function returns the value of a given key in cache, and a boolean showing if the key is or is not present.
type LruReadThroughCache ¶
type LruReadThroughCache struct {
// contains filtered or unexported fields
}
LruReadThroughCache implemets a "Last Recent Used" cache with a storage backend. Therefore, "writes" are done in-memory, but "reads" are done checking the storage. It uses an "evictList" for the LRU functionality.
func NewLruReadThroughCache ¶
func NewLruReadThroughCache(table storage.Table, store storage.Store, cacheSize uint16) *LruReadThroughCache
NewLruReadThroughCache returns a new cacheSize cache with an asociated storage.
func (*LruReadThroughCache) Fill ¶
func (c *LruReadThroughCache) Fill(r storage.KVPairReader) (err error)
Fill function inserts a bulk of key/value elements into the cache.
func (LruReadThroughCache) Get ¶
func (c LruReadThroughCache) Get(key []byte) ([]byte, bool)
Get function returns the value of a given key in cache. If it is not present, it looks on the storage. Finally it returns a boolean showing if the key is or is not present.
func (*LruReadThroughCache) Put ¶
func (c *LruReadThroughCache) Put(key []byte, value []byte)
Put function adds a new key/value element to the in-memory cache, or updates it if it exists. It also updates the LRU eviction list.
func (*LruReadThroughCache) Size ¶
func (c *LruReadThroughCache) Size() int
Size function returns the number of items currently in the cache.
type ModifiableCache ¶
type PassThroughCache ¶
type PassThroughCache struct {
// contains filtered or unexported fields
}
PassThroughCache is not a cache itself. It stores data directly on disk.
func NewPassThroughCache ¶
func NewPassThroughCache(table storage.Table, store storage.Store) *PassThroughCache
NewPassThroughCache initializes a cache with the given underlaying storage.
type SimpleCache ¶
type SimpleCache struct {
// contains filtered or unexported fields
}
SimpleCache is a fixed size in-memory map of byte array as key and values.
func NewSimpleCache ¶
func NewSimpleCache(initialSize uint64) *SimpleCache
NewSimpleCache returns an empty SimpleCache of 'initialSize' size.
func (SimpleCache) Equal ¶
func (c SimpleCache) Equal(o *SimpleCache) bool
Equal function checks if every element from current cache (C) exists in the cache to compare (O). It does not check that every element from (O) exists in current cache (C).
func (*SimpleCache) Fill ¶
func (c *SimpleCache) Fill(r storage.KVPairReader) (err error)
Fill function inserts a bulk of key/value elements into the cache.
func (SimpleCache) Get ¶
func (c SimpleCache) Get(key []byte) ([]byte, bool)
Get function returns the value of a given key in cache, and a boolean showing if the key is or is not present.
func (*SimpleCache) Put ¶
func (c *SimpleCache) Put(key []byte, value []byte)
Put function adds a key/value element to the SimpleCache.
func (SimpleCache) Size ¶
func (c SimpleCache) Size() int
Size function returns the number of items currently in the cache.