Documentation
¶
Index ¶
- type CacheHash
- func (c *CacheHash) Delete(k interface{}) (v interface{}, found bool)
- func (c *CacheHash) Eject()
- func (c *CacheHash) First() (k interface{}, v interface{})
- func (c *CacheHash) Get(k interface{}) (v interface{}, found bool)
- func (c *CacheHash) GetNoMove(k interface{}) (v interface{}, found bool)
- func (c *CacheHash) Has(k interface{}) bool
- func (c *CacheHash) Init(maxLen int)
- func (c *CacheHash) Last() (k interface{}, v interface{})
- func (c *CacheHash) Len() int
- func (c *CacheHash) RegisterCB(newCB func(interface{}, interface{}))
- func (c *CacheHash) Upsert(k interface{}, v interface{}) (didExist, didEject bool)
- type ShardedCacheHash
- func (c *ShardedCacheHash) Add(k interface{}, v interface{}) (didExist, didEject bool)
- func (c *ShardedCacheHash) Delete(k interface{}) (interface{}, bool)
- func (c *ShardedCacheHash) Get(k interface{}) (interface{}, bool)
- func (c *ShardedCacheHash) GetNoMove(k interface{}) (interface{}, bool)
- func (c *ShardedCacheHash) Has(k interface{}) bool
- func (c *ShardedCacheHash) Init(maxLen int, shards int)
- func (c *ShardedCacheHash) Lock(k interface{})
- func (c *ShardedCacheHash) RegisterCB(newCB func(interface{}, interface{}))
- func (c *ShardedCacheHash) Unlock(k interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheHash ¶
CacheHash is an LRU cache implemented with a hash map and a doubly linked list. The list stores key-value pairs in the order they were accessed, with the most recently accessed key-value pair at the front of the list. This allows for O(1) insertions, deletions, and lookups and ensures the most recently accesssed elements are persisted in the cache.
func (*CacheHash) Delete ¶
Delete removes the key-value pair from the cache and returns the value and whether the key was found. v is nil if the key was not found.
func (*CacheHash) Eject ¶
func (c *CacheHash) Eject()
Eject removes the least-recently used key-value pair from the cache.
func (*CacheHash) First ¶
func (c *CacheHash) First() (k interface{}, v interface{})
First returns the key-value pair at the front of the list. Returns nil, nil if the cache is empty.
func (*CacheHash) Get ¶
Get returns the value associated with the key and whether the key was found in the cache. It also moves it to the front of the list. v is nil if the key was not found.
func (*CacheHash) GetNoMove ¶
GetNoMove returns the value associated with the key and whether the key was found in the cache.
func (*CacheHash) Last ¶
func (c *CacheHash) Last() (k interface{}, v interface{})
Last returns the key-value pair at the back of the list. Returns nil, nil if the cache is empty.
func (*CacheHash) RegisterCB ¶
func (c *CacheHash) RegisterCB(newCB func(interface{}, interface{}))
RegisterCB registers a callback function to be called when an element is ejected from the cache.
func (*CacheHash) Upsert ¶
Upsert upserts a new key-value pair into the cache. If the key already exists, the value is updated and the key is moved to the front of the list. If the key does not exist in the cache, the key-value pair is added to the front of the list. Returns whether the key already existed in the cache and if the cache had to eject an entry to insert this one.
type ShardedCacheHash ¶
type ShardedCacheHash struct {
// contains filtered or unexported fields
}
func (*ShardedCacheHash) Add ¶
func (c *ShardedCacheHash) Add(k interface{}, v interface{}) (didExist, didEject bool)
func (*ShardedCacheHash) Delete ¶
func (c *ShardedCacheHash) Delete(k interface{}) (interface{}, bool)
func (*ShardedCacheHash) Get ¶
func (c *ShardedCacheHash) Get(k interface{}) (interface{}, bool)
func (*ShardedCacheHash) GetNoMove ¶
func (c *ShardedCacheHash) GetNoMove(k interface{}) (interface{}, bool)
func (*ShardedCacheHash) Has ¶
func (c *ShardedCacheHash) Has(k interface{}) bool
func (*ShardedCacheHash) Init ¶
func (c *ShardedCacheHash) Init(maxLen int, shards int)
func (*ShardedCacheHash) Lock ¶
func (c *ShardedCacheHash) Lock(k interface{})
func (*ShardedCacheHash) RegisterCB ¶
func (c *ShardedCacheHash) RegisterCB(newCB func(interface{}, interface{}))
func (*ShardedCacheHash) Unlock ¶
func (c *ShardedCacheHash) Unlock(k interface{})