cache

package
v0.0.2-rc-ci Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Favorites

type Favorites[T any] struct {
	// contains filtered or unexported fields
}

Favorites implements a generic key value storage, with a maximum number of entries. It keeps track of reads to favor keys with more reads when the cache has reached the maximum of entries. It is save for concurrent usage.

func NewFavoritesCache

func NewFavoritesCache[T any](maxEntries int) *Favorites[T]

NewFavoritesCache returns a newly initialized favorites cache with a given maximum number of entries.

func (*Favorites[T]) Clear

func (c *Favorites[T]) Clear()

Clear resets the internal state.

func (*Favorites[T]) Get

func (c *Favorites[T]) Get(key string) (T, bool)

Get returns the value for the given key when available. The second return value indicates, wether a value was for for the given key.

func (*Favorites[T]) Set

func (c *Favorites[T]) Set(key string, value T)

Set takes a key and value an stores them. If the storage already has reached its maximum amount of entries, the entry with the least reads will be overridden.

Jump to

Keyboard shortcuts

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