Documentation
¶
Overview ¶
lrucache implements a simple memory-based LRU cache.
Index ¶
- Variables
- type Cache
- func (cache *Cache) Add(key Key, value Value) (err error)
- func (cache *Cache) Get(key Key) (value Value, err error)
- func (cache *Cache) Len() (n int)
- func (cache *Cache) Purge()
- func (cache *Cache) Remove(key Key) (err error)
- func (cache *Cache) Set(key Key, value Value) (err error)
- func (cache *Cache) SetSize(size int)
- func (cache *Cache) Size() (size int)
- type Key
- type Value
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = errors.New("item not found") ErrNotStored = errors.New("item not stored") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thread-safe fixed size LRU cache.
func (*Cache) Add ¶
Add adds key-value to cache. if there already exists a item with the same key, it returns ErrNotStored.
NOTE: the comparison operators == and != must be fully defined for operands of the key type.
func (*Cache) Get ¶
Get looks up a key's value from the cache. if there is no such item with the key it returns ErrNotFound.
NOTE: the comparison operators == and != must be fully defined for operands of the key type.
func (*Cache) Remove ¶
Remove removes the provided key from the cache. if there is no such item with the key it returns ErrNotFound, normally you can ignore this error.
NOTE: the comparison operators == and != must be fully defined for operands of the key type.
func (*Cache) Set ¶
Set sets key-value to cache, unconditional
NOTE: the comparison operators == and != must be fully defined for operands of the key type.
Click to show internal directories.
Click to hide internal directories.