Documentation ¶
Index ¶
- type CachedResponse
- type Item
- type LRUCache
- func (lru *LRUCache) Capacity() int64
- func (lru *LRUCache) Delete(key string) bool
- func (lru *LRUCache) Get(key string) (v *CachedResponse, ok bool)
- func (lru *LRUCache) Length() int64
- func (lru *LRUCache) Reset()
- func (lru *LRUCache) Set(key string, value *CachedResponse)
- func (lru *LRUCache) SetIfAbsent(key string, value *CachedResponse)
- func (lru *LRUCache) Size() int64
- func (c *LRUCache) StartGC()
- func (lru *LRUCache) Stats() (length, size, capacity int64, oldest time.Time)
- func (c *LRUCache) StopGC()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedResponse ¶
func (*CachedResponse) Size ¶
func (cp *CachedResponse) Size() int
type Item ¶
type Item struct { Key string Value CachedResponse }
Item is what is stored in the cache
type LRUCache ¶
type LRUCache struct { OnEviction func(key string) // contains filtered or unexported fields }
LRUCache is a typical LRU cache implementation. If the cache reaches the capacity, the least recently used item is deleted from the cache. Note the capacity is not the number of items, but the total sum of the Size() of each item.
func NewLRUCache ¶
NewLRUCache creates a new empty cache with the given capacity.
func (*LRUCache) Get ¶
func (lru *LRUCache) Get(key string) (v *CachedResponse, ok bool)
Get returns a value from the cache, and marks the entry as most recently used.
func (*LRUCache) Set ¶
func (lru *LRUCache) Set(key string, value *CachedResponse)
Set sets a value in the cache.
func (*LRUCache) SetIfAbsent ¶
func (lru *LRUCache) SetIfAbsent(key string, value *CachedResponse)
SetIfAbsent will set the value in the cache if not present. If the value exists in the cache, we don't set it.
func (*LRUCache) StartGC ¶
func (c *LRUCache) StartGC()
StartGC starts running a routine ticking at expiry interval, on each interval this routine does a sweep across the cache entries and garbage collects all the expired entries.