gcache

package
v0.0.0-...-25e440d Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_SIMPLE = "simple"
	TYPE_LRU    = "lru"
	TYPE_LFU    = "lfu"
	TYPE_ARC    = "arc"
)

Variables

View Source
var DefaultTTL time.Duration
View Source
var FfileCacheCap float32
View Source
var FileCacheCap, LayerCacheCap, SliceCacheCap int
View Source
var KeyNotFoundError = errors.New("Key not found.")
View Source
var Stype string

Functions

func FileHashKey

func FileHashKey(dgst string) string

func LayerHashKey

func LayerHashKey(dgst string) string

func SliceHashKey

func SliceHashKey(dgst string) string

Types

type ARC

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

Constantly balances between LRU and LFU, to improve the combined result.

func (*ARC) Get

func (c *ARC) Get(key interface{}) (interface{}, error)

Get a value from cache pool using key if it exists. If not exists and it has LoaderFunc, it will generate the value using you have specified LoaderFunc method returns value.

func (*ARC) GetALL

func (c *ARC) GetALL(checkExpired bool) map[interface{}]interface{}

GetALL returns all key-value pairs in the cache.

func (*ARC) GetIFPresent

func (c *ARC) GetIFPresent(key interface{}) (interface{}, error)

GetIFPresent gets a value from cache pool using key if it exists. If it dose not exists key, returns KeyNotFoundError. And send a request which refresh value for specified key if cache object has LoaderFunc.

func (*ARC) Has

func (c *ARC) Has(key interface{}) bool

Has checks if key exists in cache

func (*ARC) Keys

func (c *ARC) Keys(checkExpired bool) []interface{}

Keys returns a slice of the keys in the cache.

func (*ARC) Len

func (c *ARC) Len(checkExpired bool) int

Len returns the number of items in the cache.

func (*ARC) Purge

func (c *ARC) Purge()

Purge is used to completely clear the cache

func (*ARC) Remove

func (c *ARC) Remove(key interface{}) bool

Remove removes the provided key from the cache.

func (*ARC) Set

func (c *ARC) Set(key interface{}, value interface{}) error

func (*ARC) SetWithExpire

func (c *ARC) SetWithExpire(key interface{}, value interface{}, expiration time.Duration) error

Set a new key-value pair with an expiration time

func (*ARC) Size

func (c *ARC) Size(checkExpired bool) int

Size returns the actually size of total stored items in the cache

type AddedFunc

type AddedFunc func(interface{}, interface{})

type BlobCache

type BlobCache struct {
	MemCache  *bigcache.BigCache
	DiskCache *diskv.Diskv

	FileLST  Cache
	LayerLST Cache
	SliceLST Cache
	StageLST Cache
}

preconstruction cache

func (*BlobCache) GetFile

func (cache *BlobCache) GetFile(dgst string) ([]byte, bool, float64)

func (*BlobCache) GetLayer

func (cache *BlobCache) GetLayer(dgst string) ([]byte, bool)

func (*BlobCache) GetSlice

func (cache *BlobCache) GetSlice(dgst string) ([]byte, bool)

func (*BlobCache) Init

func (cache *BlobCache) Init() error

func (*BlobCache) RemovePUTLayer

func (cache *BlobCache) RemovePUTLayer(dgst string, move_tocache bool) bool

func (*BlobCache) SetCapTTL

func (cache *BlobCache) SetCapTTL(fileCacheCap, layerCacheCap, sliceCacheCap, ttl int,
	stype string) error

func (*BlobCache) SetFile

func (cache *BlobCache) SetFile(dgst string, bss []byte) bool

func (*BlobCache) SetLayer

func (cache *BlobCache) SetLayer(dgst string, bss []byte) bool

func (*BlobCache) SetPUTLayer

func (cache *BlobCache) SetPUTLayer(dgst string, size int64, bpath string) bool

func (*BlobCache) SetSlice

func (cache *BlobCache) SetSlice(dgst string, bss []byte) bool

type Cache

type Cache interface {
	Set(key, value interface{}) error
	SetWithExpire(key, value interface{}, expiration time.Duration) error
	Get(key interface{}) (interface{}, error)
	GetIFPresent(key interface{}) (interface{}, error)
	GetALL(checkExpired bool) map[interface{}]interface{}

	Remove(key interface{}) bool
	Purge()
	Keys(checkExpired bool) []interface{}
	Len(checkExpired bool) int
	Size(checkExpired bool) int
	Has(key interface{}) bool
	// contains filtered or unexported methods
}

type CacheBuilder

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

func New

func New(size int) *CacheBuilder

func (*CacheBuilder) ARC

func (cb *CacheBuilder) ARC() *CacheBuilder

func (*CacheBuilder) AddedFunc

func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder

func (*CacheBuilder) Build

func (cb *CacheBuilder) Build() Cache

func (*CacheBuilder) Clock

func (cb *CacheBuilder) Clock(clock Clock) *CacheBuilder

func (*CacheBuilder) DeserializeFunc

func (cb *CacheBuilder) DeserializeFunc(deserializeFunc DeserializeFunc) *CacheBuilder

func (*CacheBuilder) EvictType

func (cb *CacheBuilder) EvictType(tp string) *CacheBuilder

func (*CacheBuilder) EvictedFunc

func (cb *CacheBuilder) EvictedFunc(evictedFunc EvictedFunc) *CacheBuilder

func (*CacheBuilder) Expiration

func (cb *CacheBuilder) Expiration(expiration time.Duration) *CacheBuilder

func (*CacheBuilder) LFU

func (cb *CacheBuilder) LFU() *CacheBuilder

func (*CacheBuilder) LRU

func (cb *CacheBuilder) LRU() *CacheBuilder

func (*CacheBuilder) LoaderExpireFunc

func (cb *CacheBuilder) LoaderExpireFunc(loaderExpireFunc LoaderExpireFunc) *CacheBuilder

Set a loader function with expiration. loaderExpireFunc: create a new value with this function if cached value is expired. If nil returned instead of time.Duration from loaderExpireFunc than value will never expire.

func (*CacheBuilder) LoaderFunc

func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder

Set a loader function. loaderFunc: create a new value with this function if cached value is expired.

func (*CacheBuilder) PurgeVisitorFunc

func (cb *CacheBuilder) PurgeVisitorFunc(purgeVisitorFunc PurgeVisitorFunc) *CacheBuilder

func (*CacheBuilder) SerializeFunc

func (cb *CacheBuilder) SerializeFunc(serializeFunc SerializeFunc) *CacheBuilder

func (*CacheBuilder) Simple

func (cb *CacheBuilder) Simple() *CacheBuilder

type Clock

type Clock interface {
	Now() time.Time
}

func NewRealClock

func NewRealClock() Clock

type DeserializeFunc

type DeserializeFunc func(interface{}, interface{}) (interface{}, error)

type EvictedFunc

type EvictedFunc func(interface{}, interface{})

type FakeClock

type FakeClock interface {
	Clock

	Advance(d time.Duration)
}

func NewFakeClock

func NewFakeClock() FakeClock

type Group

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

Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.

func (*Group) Do

func (g *Group) Do(key interface{}, fn func() (interface{}, error), isWait bool) (interface{}, bool, error)

Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.

type LFUCache

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

Discards the least frequently used items first.

func (*LFUCache) Get

func (c *LFUCache) Get(key interface{}) (interface{}, error)

Get a value from cache pool using key if it exists. If it dose not exists key and has LoaderFunc, generate a value using `LoaderFunc` method returns value.

func (*LFUCache) GetALL

func (c *LFUCache) GetALL(checkExpired bool) map[interface{}]interface{}

GetALL returns all key-value pairs in the cache.

func (*LFUCache) GetIFPresent

func (c *LFUCache) GetIFPresent(key interface{}) (interface{}, error)

GetIFPresent gets a value from cache pool using key if it exists. If it dose not exists key, returns KeyNotFoundError. And send a request which refresh value for specified key if cache object has LoaderFunc.

func (*LFUCache) Has

func (c *LFUCache) Has(key interface{}) bool

Has checks if key exists in cache

func (*LFUCache) Keys

func (c *LFUCache) Keys(checkExpired bool) []interface{}

Keys returns a slice of the keys in the cache.

func (*LFUCache) Len

func (c *LFUCache) Len(checkExpired bool) int

Len returns the number of items in the cache.

func (*LFUCache) Purge

func (c *LFUCache) Purge()

Completely clear the cache

func (*LFUCache) Remove

func (c *LFUCache) Remove(key interface{}) bool

Remove removes the provided key from the cache.

func (*LFUCache) Set

func (c *LFUCache) Set(key, value interface{}) error

Set a new key-value pair

func (*LFUCache) SetWithExpire

func (c *LFUCache) SetWithExpire(key, value interface{}, expiration time.Duration) error

Set a new key-value pair with an expiration time

func (*LFUCache) Size

func (c *LFUCache) Size(checkExpired bool) int

type LRUCache

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

Discards the least recently used items first.

func (*LRUCache) Get

func (c *LRUCache) Get(key interface{}) (interface{}, error)

Get a value from cache pool using key if it exists. If it dose not exists key and has LoaderFunc, generate a value using `LoaderFunc` method returns value.

func (*LRUCache) GetALL

func (c *LRUCache) GetALL(checkExpired bool) map[interface{}]interface{}

GetALL returns all key-value pairs in the cache.

func (*LRUCache) GetIFPresent

func (c *LRUCache) GetIFPresent(key interface{}) (interface{}, error)

GetIFPresent gets a value from cache pool using key if it exists. If it dose not exists key, returns KeyNotFoundError. And send a request which refresh value for specified key if cache object has LoaderFunc.

func (*LRUCache) Has

func (c *LRUCache) Has(key interface{}) bool

Has checks if key exists in cache

func (*LRUCache) Keys

func (c *LRUCache) Keys(checkExpired bool) []interface{}

Keys returns a slice of the keys in the cache.

func (*LRUCache) Len

func (c *LRUCache) Len(checkExpired bool) int

Len returns the number of items in the cache.

func (*LRUCache) Purge

func (c *LRUCache) Purge()

Completely clear the cache

func (*LRUCache) Remove

func (c *LRUCache) Remove(key interface{}) bool

Remove removes the provided key from the cache.

func (*LRUCache) Set

func (c *LRUCache) Set(key, value interface{}) error

set a new key-value pair

func (*LRUCache) SetWithExpire

func (c *LRUCache) SetWithExpire(key, value interface{}, expiration time.Duration) error

Set a new key-value pair with an expiration time

func (*LRUCache) Size

func (c *LRUCache) Size(checkExpired bool) int

type LoaderExpireFunc

type LoaderExpireFunc func(interface{}) (interface{}, *time.Duration, error)

type LoaderFunc

type LoaderFunc func(interface{}) (interface{}, error)

type PurgeVisitorFunc

type PurgeVisitorFunc func(interface{}, interface{})

type RealClock

type RealClock struct{}

func (RealClock) Now

func (rc RealClock) Now() time.Time

type SerializeFunc

type SerializeFunc func(interface{}, interface{}) (interface{}, error)

type SimpleCache

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

SimpleCache has no clear priority for evict cache. It depends on key-value map order.

func (*SimpleCache) Get

func (c *SimpleCache) Get(key interface{}) (interface{}, error)

Get a value from cache pool using key if it exists. If it dose not exists key and has LoaderFunc, generate a value using `LoaderFunc` method returns value.

func (*SimpleCache) GetALL

func (c *SimpleCache) GetALL(checkExpired bool) map[interface{}]interface{}

GetALL returns all key-value pairs in the cache.

func (*SimpleCache) GetIFPresent

func (c *SimpleCache) GetIFPresent(key interface{}) (interface{}, error)

GetIFPresent gets a value from cache pool using key if it exists. If it dose not exists key, returns KeyNotFoundError. And send a request which refresh value for specified key if cache object has LoaderFunc.

func (*SimpleCache) Has

func (c *SimpleCache) Has(key interface{}) bool

Has checks if key exists in cache

func (*SimpleCache) Keys

func (c *SimpleCache) Keys(checkExpired bool) []interface{}

Keys returns a slice of the keys in the cache.

func (*SimpleCache) Len

func (c *SimpleCache) Len(checkExpired bool) int

Len returns the number of items in the cache.

func (*SimpleCache) Purge

func (c *SimpleCache) Purge()

Completely clear the cache

func (*SimpleCache) Remove

func (c *SimpleCache) Remove(key interface{}) bool

Remove removes the provided key from the cache.

func (*SimpleCache) Set

func (c *SimpleCache) Set(key, value interface{}) error

Set a new key-value pair

func (*SimpleCache) SetWithExpire

func (c *SimpleCache) SetWithExpire(key, value interface{}, expiration time.Duration) error

Set a new key-value pair with an expiration time

func (*SimpleCache) Size

func (c *SimpleCache) Size(checkExpired bool) int

Jump to

Keyboard shortcuts

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