Documentation ¶
Overview ¶
Package lfucache an in memory least frequently used (LFU) cache. All operations have with O(1) complexity. When evicting an item from the cache, if 2 items have the same frequency the (least recently used) LRU item is evicted.
Ideally, you should provide a wrapper around this class to ensure strict type checks for keys and values that can be put into the cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCacheMiss is the error that is returned when there is a Cache during a Get operation ErrCacheMiss = errors.New("cache miss") // ErrInvalidCap is the error returned when the cache cap is invalid ErrInvalidCap = errors.New("cache cap <= 0") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the data structure for the LFU Cache. The zero value of this cache is not ready to use because the cap is zero
func New ¶
New creates a new instance of the LFU Cache. It returns and ErrInvalidCap error if the cap <= 0.
func (*Cache) Get ¶
Get returns an item for the Cache having a key. It returns ErrCacheMiss if there's a Cache miss.