import "github.com/byte-mug/golang-rlogc/cache"
This package implements a fixed-size thread safe *R+log(C)* cache.
type Cache struct { // contains filtered or unexported fields }
-
func NewCache(decay float64, timer rlogc.Timer, size int, cb EvictCB) *Cache
-
func (c *Cache) Add(key, value interface{}) (evicted bool)
Adds or replaces a cache entry.
func (c *Cache) Contains(key interface{}) bool
Looks up a cache entry without updating the cache statistics and witout returning it's value.
func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool)
-
func (c *Cache) Get(key interface{}) (value interface{}, ok bool)
Looks up a cache entry.
func (c *Cache) GetOldest() (key interface{}, value interface{}, ok bool)
-
func (c *Cache) Len() int
Returns the number of entries.
func (c *Cache) Peek(key interface{}) (value interface{}, ok bool)
Looks up a cache entry without updating the cache statistics.
func (c *Cache) PeekOrAdd(key, value interface{}) (previous interface{}, ok, evicted bool)
Looks up a cache entry without updating the cache statistics and adds a new entry, if no cache entry was found.
func (c *Cache) Remove(key interface{}) (present bool)
Removes a specific cache entry.
func (c *Cache) RemoveOldest() (key interface{}, value interface{}, ok bool)
-
func (c *Cache) Resize(size int) (evicted int)
-
type EvictCB func(key, value interface{})
EvictCB is used to get a callback when a cache entry is evicted.
import "github.com/byte-mug/golang-rlogc/rlogc"
import "sync"
import "unsafe"