Documentation ¶
Index ¶
- Constants
- type Cache
- func (c *Cache) Erase(key string) (value ValueType)
- func (c *Cache) Insert(key string, value ValueType) ([]ValueType, error)
- func (c *Cache) LookUp(key string) (value ValueType)
- func (c *Cache) LookUpWithoutChangingOrder(key string) (value ValueType)
- func (c *Cache) UpdateWithoutChangingOrder(key string, value ValueType) error
- type ValueType
Constants ¶
const ( InvalidEntrySizeErrorMsg = "size of the entry is more than the cache's maxSize" InvalidEntryErrorMsg = "nil values are not supported" InvalidUpdateEntrySizeErrorMsg = "size of entry to be updated is not same as existing size" EntryNotExistErrMsg = "entry with given key does not exist" )
Predefined error messages returned by the Cache.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a LRU cache for any lru.ValueType indexed by string keys. That means entry's value should be a lru.ValueType.
func NewCache ¶
NewCache returns the reference of cache object by initialising the cache with the supplied maxSize, which must be greater than zero.
func (*Cache) Insert ¶
Insert the supplied value into the cache, overwriting any previous entry for the given key. The value must be non-nil. Also returns a slice of ValueType evicted by the new inserted entry.
func (*Cache) LookUp ¶
LookUp a previously-inserted value for the given key. Return nil if no value is present.
func (*Cache) LookUpWithoutChangingOrder ¶
LookUpWithoutChangingOrder looks up previously-inserted value for a given key without changing the order of entries in the cache. Return nil if no value is present.
Note: Because this look up doesn't change the order, it only acquires and releases read lock.
func (*Cache) UpdateWithoutChangingOrder ¶
UpdateWithoutChangingOrder updates entry with the given key in cache with given value without changing order of entries in cache, returning error if an entry with given key doesn't exist. Also, the size of value for entry shouldn't be updated with this method (use c.Insert for updating size).