Documentation ¶
Index ¶
- Constants
- type LRUCache
- func (cache *LRUCache) Add(args request.CacheRequest) response.CacheResponse
- func (cache *LRUCache) CountKeys(args request.CacheRequest) response.CacheResponse
- func (cache *LRUCache) Delete(args request.CacheRequest) response.CacheResponse
- func (cache *LRUCache) DeleteByKey(key string) response.CacheResponse
- func (cache *LRUCache) Flush(args request.CacheRequest) response.CacheResponse
- func (cache *LRUCache) Get(args request.CacheRequest) response.CacheResponse
- func (cache *LRUCache) GetHashtableReference() *map[string]*Node
- func (cache *LRUCache) Put(args request.CacheRequest) response.CacheResponse
- type List
- type Node
Constants ¶
const ( CACHE_MISS = "CACHE_MISS" STORED = "STORED" NOT_STORED = "NOT_STORED" REMOVED = "REMOVED" NOT_FOUND = "NOT_FOUND" FLUSHED = "FLUSH" ERR_FLUSH = "ERR_FLUSH" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRUCache ¶
type LRUCache struct { // Size represents the maximum number of allowable // key-value pairs in the cache. Size int32 // Count records the number of key-value pairs // currently in the cache. Count int32 // Full tracks if Count is equal to Size Full bool // DLL is a doubly linked list containing all key-value pairs DLL *List `json:"omitempty"` // Hashtable maps to nodes in the doubly linked list Hashtable map[string]*Node // Mux is a mutex lock Mux sync.Mutex }
LRUCache represents a cache object
func (*LRUCache) Add ¶
func (cache *LRUCache) Add(args request.CacheRequest) response.CacheResponse
Add will add a key/value pair to the cache if the key does not exist already. It will not evict a key/value pair from the cache. If the cache is full, the key/value pair does not get added.
func (*LRUCache) CountKeys ¶
func (cache *LRUCache) CountKeys(args request.CacheRequest) response.CacheResponse
CountKeys return the number of keys in the cache
func (*LRUCache) Delete ¶
func (cache *LRUCache) Delete(args request.CacheRequest) response.CacheResponse
Delete removes a key/value pair from the cache Returns NOT_FOUND if the key does not exist.
func (*LRUCache) DeleteByKey ¶
func (cache *LRUCache) DeleteByKey(key string) response.CacheResponse
DeleteByKey functions the same as Delete, however it is used in various locations to reduce the cost of allocating request objects for internal deletion mechanisms e.g. the cache crawlers.
func (*LRUCache) Flush ¶
func (cache *LRUCache) Flush(args request.CacheRequest) response.CacheResponse
Flush removes all key/value pairs from the cache even if they have not expired
func (*LRUCache) Get ¶
func (cache *LRUCache) Get(args request.CacheRequest) response.CacheResponse
Get will fetch a key/value pair from the cache
func (*LRUCache) GetHashtableReference ¶
func (*LRUCache) Put ¶
func (cache *LRUCache) Put(args request.CacheRequest) response.CacheResponse
Put will add a key/value pair to the cache, possibly overwriting an existing key/value pair. Put will evict a key/value pair if the cache is full.
type List ¶
type List struct { // Head is the head node. It is a special case node. // It does not get populated and is a reference node // for accessing the most recently used key-value pair. Head *Node `json:"-"` // Tail is the tail node. It is a special case node. // It does not get populated and is a reference node // for accessing the least recently used key-value pair. Tail *Node `json:"-"` // Size is the size of the list. Size int32 Mux sync.Mutex }
type Node ¶
type Node struct { // Key of the key-value pair Key string // Value of the key-value pair Value interface{} // TTL is the time-to-live for the key-value pair TTL int64 // CreatedAt is the time the key-value pair was entered // into the cache. CreatedAt int64 // Prev points to the previous node in the doubly // linked list. Omit this from snapshot serialization. Prev *Node `json:"-"` // Next points to the next node in the doubly linked // list. Omit this from snapshot serialization. Next *Node `json:"-"` // Mux is a mutex lock. Mux sync.Mutex }
func RemoveLast ¶
RemoveLast removes the least recently used item in the list.