Documentation ¶
Overview ¶
Package lru provides a goroutine safe LRU cache implementation based on "github.com/golang/groupcache/lru".
Basic example:
// Creates a cache cache := lru.NewCache(MaxCachedFileNum, MaxCachedSize, func(key, object interface{}) { // Jobs to do on evicted }) // Caches an object cache.Add(Key, CachedObj, CachedObjSize) // Gets a cached object cachedObj, ok := cache.Get(Key)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a goroutine safe LRU cache base on "github.com/golang/groupcache/lru".
func NewCache ¶
NewCache creates a ready-to-use Cache.
maxEntries: Limit of cached objects, LRU eviction will be triggered when reached. maxCachedSize: Limit of total cached objects' size in bytes, LRU eviction will be triggered when reached. onEvicted: Optionally specificies a callback function to be executed when an entry is purged from the cache.
func (*Cache) Add ¶
Add adds an object to the cache, LRU eviction will be triggered if limit reached after adding.
key: Key of the cached object. object: Object to be cached. objectSize: Size in bytes of the cached object.
func (*Cache) CurCachedSize ¶
CurCachedSize returns the total cached objects' size in bytes.
func (*Cache) Get ¶
Get looks up a key's object from the cache. It returns true and the object if found, false and nil otherwise.
func (*Cache) Remove ¶
func (c *Cache) Remove(key interface{})
Remove removes a key's object from the cache.
func (*Cache) RemoveCachedObjects ¶
func (c *Cache) RemoveCachedObjects(keys []interface{})
RemoveCachedObjects removes objects specified in `keys` from the cache.