Documentation
¶
Overview ¶
Package cache provides cache implementations for the application layer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU[K comparable, V any] struct { // contains filtered or unexported fields }
LRU is a thread-safe LRU (Least Recently Used) cache with a fixed capacity. It implements port.Cache[K, V].
When the cache reaches capacity, the least recently accessed entry is evicted to make room for new entries. Both Get and Set operations mark an entry as recently used.
func NewLRU ¶
func NewLRU[K comparable, V any](capacity int) *LRU[K, V]
NewLRU creates a new LRU cache with the given capacity. Capacity must be positive; if zero or negative, a capacity of 1 is used.
func (*LRU[K, V]) Get ¶
Get retrieves a value by key and marks it as recently used. Returns the value and true if found, or the zero value and false if not found.
Click to show internal directories.
Click to hide internal directories.