gencache

package
v0.0.0-...-9edf4cd Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenCache

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

GenCache is a generic cache of any type of value V, keyed by a comparable key K.

func NewGenCache

func NewGenCache[K comparable, V any](memLimit uint32, itemLimit uint32) *GenCache[K, V]

NewGenCache returns a new GenCache.

func (*GenCache[K, V]) Delete

func (self *GenCache[K, V]) Delete(key K) (exists bool)

Delete deletes entry under key from cache if it exists and returns truth if it was found and deleted.

func (*GenCache[K, V]) Exists

func (self *GenCache[K, V]) Exists(key K) (exists bool)

Returns truth if entry under key exists in cache.

func (*GenCache[K, V]) Get

func (self *GenCache[K, V]) Get(key K) (value V, found bool)

Get retrieves an item from cache by id and true if found. Otherwise returns zero value of V and false.

func (*GenCache[K, V]) Put

func (self *GenCache[K, V]) Put(key K, data V) (old V, replaced bool)

Put stores buf into cache under id and rotates the cache if storage limit has been reached. It returns the old value if one existed at specified id and true or zero value of v and false otherwise.

func (*GenCache[K, V]) Usage

func (self *GenCache[K, V]) Usage() (used uint32)

Usage returns current memory usage in bytes.

type SyncGenCache

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

SyncGenCache is the concurrency safe version of GenCache.

func NewSyncGenCache

func NewSyncGenCache[K comparable, V any](memLimit uint32, itemLimit uint32) *SyncGenCache[K, V]

NewSyncGenCache returns a new SyncGenCache.

func (*SyncGenCache[K, V]) Delete

func (self *SyncGenCache[K, V]) Delete(key K) (exists bool)

Delete deletes entry under key from cache if it exists and returns truth if it was found and deleted.

func (*SyncGenCache[K, V]) Exists

func (self *SyncGenCache[K, V]) Exists(key K) (exists bool)

Returns truth if entry under key exists in cache.

func (*SyncGenCache[K, V]) Get

func (self *SyncGenCache[K, V]) Get(key K) (value V, found bool)

Get retrieves an item from cache by id and true if found. Otherwise returns zero value of V and false.

func (*SyncGenCache[K, V]) Put

func (self *SyncGenCache[K, V]) Put(key K, data V) (old V, replaced bool)

Put stores buf into cache under id and rotates the cache if storage limit has been reached. It returns the old value if one existed at specified id and true or zero value of v and false otherwise.

func (*SyncGenCache[K, V]) Usage

func (self *SyncGenCache[K, V]) Usage() (used uint32)

Usage returns current memory usage in bytes.

Jump to

Keyboard shortcuts

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