Documentation ¶
Index ¶
- Variables
- func NewRistrettoCache(maxEntries, maxCost int64, cost func(interface{}) int64) *ristretto.Cache
- type Cache
- type Config
- type Item
- type LRUCache
- func (lru *LRUCache) Clear()
- func (lru *LRUCache) Delete(key string)
- func (lru *LRUCache) Evictions() int64
- func (lru *LRUCache) ForEach(callback func(value interface{}) bool)
- func (lru *LRUCache) Get(key string) (v interface{}, ok bool)
- func (lru *LRUCache) Items() []Item
- func (lru *LRUCache) Len() int
- func (lru *LRUCache) MaxCapacity() int64
- func (lru *LRUCache) Set(key string, value interface{}) bool
- func (lru *LRUCache) SetCapacity(capacity int64)
- func (lru *LRUCache) UsedCapacity() int64
- func (lru *LRUCache) Wait()
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = &Config{ MaxEntries: 5000, MaxMemoryUsage: 32 * 1024 * 1024, LFU: true, }
DefaultConfig is the default configuration for a cache instance in Vitess
Functions ¶
Types ¶
type Cache ¶
type Cache interface { Get(key string) (interface{}, bool) Set(key string, val interface{}) bool ForEach(callback func(interface{}) bool) Delete(key string) Clear() // Wait waits for all pending operations on the cache to settle. Since cache writes // are asynchronous, a write may not be immediately accessible unless the user // manually calls Wait. Wait() Len() int Evictions() int64 UsedCapacity() int64 MaxCapacity() int64 SetCapacity(int64) }
Cache is a generic interface type for a data structure that keeps recently used objects in memory and evicts them when it becomes full.
func NewDefaultCacheImpl ¶
NewDefaultCacheImpl returns the default cache implementation for Vitess. The options in the Config struct control the memory and entry limits for the cache, and the underlying cache implementation.
type Config ¶
type Config struct { // MaxEntries is the estimated amount of entries that the cache will hold at capacity MaxEntries int64 // MaxMemoryUsage is the maximum amount of memory the cache can handle MaxMemoryUsage int64 // LFU toggles whether to use a new cache implementation with a TinyLFU admission policy LFU bool }
Config is the configuration options for a cache instance
type LRUCache ¶
type LRUCache struct {
// 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 CachedSize() of each item.
func NewLRUCache ¶
NewLRUCache creates a new empty cache with the given capacity.
func (*LRUCache) ForEach ¶
ForEach yields all the values for the cache, ordered from most recently used to least recently used.
func (*LRUCache) Get ¶
Get returns a value from the cache, and marks the entry as most recently used.
func (*LRUCache) Items ¶
Items returns all the values for the cache, ordered from most recently used to least recently used.
func (*LRUCache) MaxCapacity ¶
MaxCapacity returns the cache maximum capacity.
func (*LRUCache) SetCapacity ¶
SetCapacity will set the capacity of the cache. If the capacity is smaller, and the current cache size exceed that capacity, the cache will be shrank.
func (*LRUCache) UsedCapacity ¶
UsedCapacity returns the size of the cache (in bytes)