cache

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Key

type Key interface {
	int | string
}

type LRU

type LRU[K Key, V any] struct {
	// contains filtered or unexported fields
}

func NewLRU

func NewLRU[K Key, V any](size int) *LRU[K, V]

func (*LRU[K, V]) Find

func (c *LRU[K, V]) Find(key K) (value V, ok bool)

func (*LRU[K, V]) Get

func (c *LRU[K, V]) Get(key K) (value V)

func (*LRU[K, V]) Remove

func (c *LRU[K, V]) Remove(key K) (value V)

func (*LRU[K, V]) Set

func (c *LRU[K, V]) Set(key K, value V)

type Loader

type Loader[K Key, V any] func(ctx context.Context, key K) (V, error)

type Lockable

type Lockable[K Key, V any] struct {
	*LRU[K, *lockableItem[V]]
	// contains filtered or unexported fields
}

func NewLockable

func NewLockable[K Key, V any](size int, loader Loader[K, V], saver Saver[K, V]) *Lockable[K, V]

func (*Lockable[K, V]) GetAndLock

func (c *Lockable[K, V]) GetAndLock(ctx context.Context, key K) (value V, err error)

func (*Lockable[K, V]) PutAndLock

func (c *Lockable[K, V]) PutAndLock(key K, value V)

func (*Lockable[K, V]) SaveAndUnlock

func (c *Lockable[K, V]) SaveAndUnlock(ctx context.Context, key K, value V) (err error)

func (*Lockable[K, V]) Unlock

func (c *Lockable[K, V]) Unlock(key K) (value V)

type Saver

type Saver[K Key, V any] func(ctx context.Context, value V) error

Jump to

Keyboard shortcuts

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