/lfu

lfu with O(1) complexity

Primary LanguageGoMIT LicenseMIT

lfu

Thead-safe Least Frequently Used (LFU) cache replacement policy implementation with O(1) complexity

Build Status Go Report Card Coverage Status godoc GitHub release

Usages

capacity = 10
// create a new LFU cache with capacity
// if capacity is set to non-positive integer
// the cache won't do any eviction
cache := lfu.New(capacity)

// set k, v
cache.Set("k1", "v1")

// get v for k
v, ok := cache.Get("k1")

// evict certain number of items
cache.Evict(1)

// get current size of lfu
size := cache.Size()

References