Documentation
¶
Index ¶
- type GenCache
- type SyncGenCache
- func (self *SyncGenCache[K, V]) Delete(key K) (exists bool)
- func (self *SyncGenCache[K, V]) Exists(key K) (exists bool)
- func (self *SyncGenCache[K, V]) Get(key K) (value V, found bool)
- func (self *SyncGenCache[K, V]) Put(key K, data V) (old V, replaced bool)
- func (self *SyncGenCache[K, V]) Usage() (used uint32)
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 ¶
Delete deletes entry under key from cache if it exists and returns truth if it was found and deleted.
func (*GenCache[K, V]) Get ¶
Get retrieves an item from cache by id and true if found. Otherwise returns zero value of V and false.
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.