Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T comparable] struct { // contains filtered or unexported fields }
Cache implements a least-recently-updated (LRU) cache with nearly O(1) lookups and inserts. Items are added to the cache up to a limit, at which point further additions will evict the least recently added item. The zero value is not valid and Caches must be created with NewCache. All Cache methods are concurrent safe.
func NewCache ¶
func NewCache[T comparable](limit int) Cache[T]
NewCache creates an initialized and empty LRU cache.
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map implements a least-recently-updated (LRU) map with nearly O(1) lookups and inserts. Items are added to the cache up to a limit, at which point further additions will evict the least recently added item. The zero value is not valid and Maps must be created with NewMap. All Map methods are concurrent safe.
func NewMap ¶
func NewMap[K comparable, V any](limit int) Map[K, V]
NewMap creates an initialized and empty LRU map.
func (*Map[K, V]) Add ¶
func (m *Map[K, V]) Add(key K, value V)
Add adds an item to the LRU map, removing the oldest item if the new item exceeds the total map capacity and is not already a member, or marking the already-present item as the most recently added item.
func (*Map[K, V]) Contains ¶
Contains checks whether key is a member of the LRU map. It does modify the priority of any items.