cache

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = errors.New("key not found in cache")

Functions

This section is empty.

Types

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cache implements a Least Frequently Used cache where if storage reaches max capacity, the least used items are evicted.

func NewCache

func NewCache(maxItems int) *Cache

NewCache creates and returns a new Cache object with storage size for up to maxItems elements.

func (*Cache) Get

func (c *Cache) Get(key any) (any, error)

Get retrieves the value of the provided key if it exists. If the key does not exist, it returns an error.

func (*Cache) Set

func (c *Cache) Set(key, val any)

Set adds a new key-value pair to the cache or updates the existing one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL