cache

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRU

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

func NewLRU

func NewLRU[T any](capacity int, onEvict OnEvict[T]) *LRU[T]

func (*LRU[T]) Get

func (l *LRU[T]) Get(key string, removeIfFound bool) *T

func (*LRU[T]) Purge

func (l *LRU[T]) Purge() error

func (*LRU[T]) Put

func (l *LRU[T]) Put(key string, value *T) error

type OnEvict

type OnEvict[T any] func(key string, value *T) error

type Value

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

Value creates a thread safe cache value accessible with Get

func (*Value[T]) Get

func (cv *Value[T]) Get(loader func() (T, error), ttl *time.Time) (T, error)

Get reads the cache value, calling the loader function to populate the cache putVal if it is not currently set. ttl sets the expiration date of the cache putVal, after which time it will be reloaded. Setting ttl to nil will prevent the cache from expiring.

Jump to

Keyboard shortcuts

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