cache

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a typed cache implementation, leveraging xsync.Map for concurrency safety.

func (*Cache[K, V]) Create

func (c *Cache[K, V]) Create(key K, val V) bool

Create stores the given key-value pair, if it does not already exist, and returns whether the provided key already existed before. Create uses xsync.Map.LoadOrStore().

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key ...K)

Delete simply removes the given keys from the typed cache if at least one key is explicitely provided. If the variadic argument remains empty, then Delete purges all internal state from the underlying sync map. Delete uses a write-lock via xsync.Map.Clear() or xsync.Map.Delete().

func (*Cache[K, V]) Exists

func (c *Cache[K, V]) Exists(key K) bool

Exists returns whether the given key is already set. Exists uses xsync.Map.Load().

func (*Cache[K, V]) Length

func (c *Cache[K, V]) Length() int

Length returns the amount of key-value pairs currently maintained in the underlying cache. Length uses xsync.Map.Size().

func (*Cache[K, V]) Search

func (c *Cache[K, V]) Search(key K) (V, bool)

Search returns the value of the given key, whether that key exists or not. Search uses a read-lock via xsync.Map.Load().

func (*Cache[K, V]) Update

func (c *Cache[K, V]) Update(key K, val V)

Update initializes the given key-value pair or overwrites it in case the given key existed before. Update uses xsync.Map.Store().

type Interface

type Interface[K comparable, V any] interface {
	Create(K, V) bool
	Delete(...K)
	Exists(K) bool
	Length() int
	Search(K) (V, bool)
	Update(K, V)
}

Interface defines a generic concurrency safe key-value cache used to communicate between packages of varying business logic.

func New

func New[K comparable, V any]() Interface[K, V]

Jump to

Keyboard shortcuts

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