cache

package
v0.3.0-docs.0...-f96dd80 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

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 Cache

type Cache interface {
	Get(key []byte) ([]byte, bool)
}

type FakeCache

type FakeCache struct {
	FixedValue []byte
	// contains filtered or unexported fields
}

func NewFakeCache

func NewFakeCache(fixedValue []byte) *FakeCache

func (FakeCache) Equal

func (c FakeCache) Equal(o *FakeCache) bool

func (*FakeCache) Fill

func (c *FakeCache) Fill(r storage.KVPairReader) error

func (FakeCache) Get

func (c FakeCache) Get(key []byte) ([]byte, bool)

func (*FakeCache) Put

func (c *FakeCache) Put(key []byte, value []byte)

func (FakeCache) Size

func (c FakeCache) Size() int

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()

func (*FakeKVPairReader) Read

func (r *FakeKVPairReader) Read(buffer []*storage.KVPair) (n int, err error)

type FreeCache

type FreeCache struct {
	// contains filtered or unexported fields
}

func NewFreeCache

func NewFreeCache(initialSize int) *FreeCache

NewFreeCache funtion returns a new cache with a parametrized size.

func (FreeCache) Equal

func (c FreeCache) Equal(o *FreeCache) 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 (*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

func (c FreeCache) 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 (*FreeCache) Put

func (c *FreeCache) Put(key []byte, value []byte)

Put function adds a new key/value pair to the cache.

func (FreeCache) Size

func (c FreeCache) Size() int

Size function returns the number of items currently in the cache.

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 ModifiableCache interface {
	Put(key []byte, value []byte)
	Fill(r storage.KVPairReader) error
	Size() int
	Cache
}

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.

func (PassThroughCache) Get

func (c PassThroughCache) Get(key []byte) ([]byte, bool)

Get function returns the value of a given key by looking for it on storage. It also returns a boolean showing if the key is or is not present.

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.

Jump to

Keyboard shortcuts

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