Documentation ¶
Overview ¶
This example demonstrates a priority queue built using the heap interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a Least-Recently-Used Most-Frequently-Accessed concurrent safe cache. All its methods are safe to call concurrently.
func NewCache ¶
NewCache constructs a new Cache ready for use. The specified size should never be bigger or roughly as big as the maximum available value for uint. evictMetrics tells the cache to collect metrics on recently evicted items, which doubles the memory size of the cache. If evictMetrics is false only normal hits and misses will be collected.
func (*Cache) Get ¶
Get retrieves an item from the cache. Its amortized worst-case complexity is ~O(log(c.Len())).
func (*Cache) Metrics ¶
func (c *Cache) Metrics() CacheMetrics
Metrics copies current metrics values and returns the snapshot. If the cache has size<=0 zero metrics will be returned.
func (*Cache) Put ¶
Put stores an item in the cache. Its amortized worst-case complexity is ~O(log(c.Len())).
type CacheMetrics ¶
type CacheMetrics struct { // HitMFA is the count of hits that returned a value from MFA. // Note that a hit on MFA will make the cache skip LRU. HitMFA uint // MissMFA is the count of misses on MFA access. MissMFA uint // HitLRU is the count of hits that returned a value from LRU. // Note that a LRU is only accessed on MFA misses. HitLRU uint // MissLRU is the count of misses on LRU access. MissLRU uint // Miss is the overall amount of misses, which means the requested key was not in MFA nor in LRU. Miss uint // RecentlyEvictedMiss is the amount of misses that had a key which was recently evicted. // If the cache is not running with evicMetrics it will be set to 0. RecentlyEvictedMiss uint }
CacheMetrics carries metrics about a cache usage.
func (CacheMetrics) Tot ¶
func (m CacheMetrics) Tot() uint
Tot returns the total amount of accesses.