Documentation ¶
Overview ¶
Package cache implements LoadingCache.
Support LRC TTL-based eviction.
Index ¶
- type LoadingCache
- func (c *LoadingCache) Close()
- func (c *LoadingCache) DeleteExpired()
- func (c *LoadingCache) Get(key string) (interface{}, bool)
- func (c *LoadingCache) Invalidate(key string)
- func (c *LoadingCache) InvalidateFn(fn func(key string) bool)
- func (c *LoadingCache) ItemCount() int
- func (c *LoadingCache) Keys() []string
- func (c *LoadingCache) Peek(key string) (interface{}, bool)
- func (c *LoadingCache) Purge()
- func (c *LoadingCache) Set(key string, value interface{})
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LoadingCache ¶
type LoadingCache struct {
// contains filtered or unexported fields
}
LoadingCache provides expirable loading cache with LRC eviction.
func NewLoadingCache ¶
func NewLoadingCache(options ...Option) (*LoadingCache, error)
NewLoadingCache returns a new expirable LRC cache, activates purge with purgeEvery (0 to never purge). Default MaxKeys is unlimited (0).
func (*LoadingCache) Close ¶
func (c *LoadingCache) Close()
Close cleans the cache and destroys running goroutines
func (*LoadingCache) DeleteExpired ¶
func (c *LoadingCache) DeleteExpired()
DeleteExpired clears cache of expired items
func (*LoadingCache) Get ¶
func (c *LoadingCache) Get(key string) (interface{}, bool)
Get returns the key value
func (*LoadingCache) Invalidate ¶
func (c *LoadingCache) Invalidate(key string)
Invalidate key (item) from the cache
func (*LoadingCache) InvalidateFn ¶
func (c *LoadingCache) InvalidateFn(fn func(key string) bool)
InvalidateFn deletes multiple keys if predicate is true
func (*LoadingCache) ItemCount ¶
func (c *LoadingCache) ItemCount() int
ItemCount return count of items in cache
func (*LoadingCache) Keys ¶
func (c *LoadingCache) Keys() []string
Keys return slice of current keys in the cache
func (*LoadingCache) Peek ¶
func (c *LoadingCache) Peek(key string) (interface{}, bool)
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
type Option ¶
type Option func(lc *LoadingCache) error
Option func type
func MaxKeys ¶
MaxKeys functional option defines how many keys to keep. By default it is 0, which means unlimited. If any non-zero MaxKeys set, default PurgeEvery will be set to 5 minutes
func PurgeEvery ¶
PurgeEvery functional option defines purge interval by default it is 0, i.e. never. If MaxKeys set to any non-zero this default will be 5minutes