{"modulePath":"github.com/omalloc/tavern","version":"v1.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lru\n\n## Types\n\n```go\ntype Cache[K comparable, V any] struct {\n\t// If len \u003e UpperBound, cache will automatically evict\n\t// down to LowerBound.  If either value is 0, this behavior\n\t// is disabled.\n\tUpperBound int\n\tLowerBound int\n\n\tEvictionChannel chan\u003c- Eviction[K, V]\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc New[K comparable, V any](cap int) *Cache[K, V]\n```\n\n```go\nfunc (c *Cache[K, V]) Evict(count int) int\n```\n\n```go\nfunc (c *Cache[K, V]) Get(key K) *V\n```\nGet retrieves the key's value if it exists, incrementing the frequency. It returns nil if there is no value for the given key.\n\n```go\nfunc (c *Cache[K, V]) GetFrequency(key K) int\n```\nGetFrequency returns the frequency count of the given key\n\n```go\nfunc (c *Cache[K, V]) Has(key K) bool\n```\nHas checks if the cache contains the given key, without incrementing the frequency.\n\n```go\nfunc (c *Cache[K, V]) Keys() []K\n```\nKeys returns all the keys in the cache\n\n```go\nfunc (c *Cache[K, V]) Len() int\n```\nLen returns the length of the cache\n\n```go\nfunc (c *Cache[K, V]) Peek(key K) *V\n```\nPeek retrieves the key's value if it exists, without incrementing the frequency. It returns nil if there is no value for the given key.\n\n```go\nfunc (c *Cache[K, V]) Purge()\n```\nPurge clears the cache.\n\n```go\nfunc (c *Cache[K, V]) Remove(key K) bool\n```\nRemove removes the given key from the cache.\n\n```go\nfunc (c *Cache[K, V]) Set(key K, value V)\n```\nSet sets given key-value in the cache. If the key-value already exists, it increases the frequency.\n\n```go\nfunc (c *Cache[K, V]) TopK(k int) []K\n```\nTopK returns the top k most frequently used keys\n\n```go\ntype Eviction[K comparable, V any] struct {\n\tKey   K\n\tValue V\n}\n```\n\n","path":"github.com/omalloc/tavern/pkg/algorithm/lru","name":"lru","synopsis":"","isRedistributable":true}
