cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultExpiration      = 12 * time.Hour
	DefaultCleanupInterval = 10 * time.Minute
	NoExpiration           = cache.NoExpiration
	ShortExpiration        = 5 * time.Minute
	OneHourExpiration      = 1 * time.Hour

	//prefixes
	PrefixDefault    = "default:"
	PrefixConnection = "connection:"
	PrefixNode       = "node:"
	PrefixThread     = "thread:"
)

Variables

View Source
var ErrCacheAlreadyExists = errors.New("cache already exists")

Functions

func Add

func Add(key string, prefix string, data any, expiration time.Duration) error

func Delete

func Delete(key string, prefix string)

func Flush

func Flush()

func Get

func Get[T any](key string, prefix string) *T

func GetValue

func GetValue[T any](key string, prefix string) (T, bool)

GetValue returns a copy of the value stored under id/prefix. It accepts both T and *T in the cache (so mixed entries after migration still work). Second return is false if not found or type mismatch.

func ListByPrefix

func ListByPrefix[T any](prefix string) []*T

func ListValuesByPrefix

func ListValuesByPrefix[T any](prefix string) []T

ListValuesByPrefix returns copies of all values in the shard with the given prefix. Accepts both T and *T in the cache (so mixed entries after migration still work).

func NewCache

func NewCache(opts *Options)

func Set

func Set(key string, prefix string, data any, expiration time.Duration)

func SetValue

func SetValue[T any](key string, prefix string, data T, expiration time.Duration)

SetValue stores a copy of data under id/prefix (value semantics).

Types

type Options

type Options struct {
	Expiration      time.Duration
	CleanupInterval time.Duration
}

Jump to

Keyboard shortcuts

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