Documentation
¶
Overview ¶
Package cache implemented some basic in memory caching strategies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU[K comparable, T any] struct { // contains filtered or unexported fields }
A cache using the Least Recently Used eviction policy.
func MustNewLRU ¶
func MustNewLRU[K comparable, T any](cap int) *LRU[K, T]
Like NewLRU but will panic on error.
func NewLRU ¶
func NewLRU[K comparable, T any](cap int) (*LRU[K, T], error)
NewLRU creates a new cache with LRU eviction policy. It accepts cap as the only argument, specifying the maximum capacity of the cache. It will return an error if cap is less than 1.
func (*LRU[K, T]) Get ¶
Get the value associated with the given key argument. Get will return collection.ErrNotFound if there is no such key, or collection.ErrIsEmpty if the cache is empty.
type MRU ¶
type MRU[K comparable, T any] struct { // contains filtered or unexported fields }
A cache using the Most Recently Used eviction policy.
func MustNewMRU ¶
func MustNewMRU[K comparable, T any](cap int) *MRU[K, T]
Like NewMRU but will panic on error.
func NewMRU ¶
func NewMRU[K comparable, T any](cap int) (*MRU[K, T], error)
NewLRU creates a new cache with LRU eviction policy. It accepts cap as the only argument, specifying the maximum capacity of the cache. Return an error if cap is less than 1.
func (*MRU[K, T]) Get ¶
Get the value associated with the given key argument. If there is no such key returns collection.ErrNotFound, or if the cache is empty then returns collection.ErrIsEmpty. This marks the key as recently used.