cache

package module
v0.0.0-...-49b3bd4 Latest Latest
Warning

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

Go to latest
Published: May 8, 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 CacheMap

type CacheMap[K goutil.Hashable, V any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[K goutil.Hashable, V any](exp time.Duration) *CacheMap[K, V]

NewCache creates a new cache map

func NewCacheCB

func NewCacheCB[K goutil.Hashable, V any](exp time.Duration) (*CacheMap[K, V], func())

NewCacheCB is just like the NewCache method, but it returns the loop in a callback function, to avoid creating more goroutines

func (*CacheMap[K, V]) Del

func (cache *CacheMap[K, V]) Del(key K)

Del removes a cache item by key

func (*CacheMap[K, V]) DelOld

func (cache *CacheMap[K, V]) DelOld(cacheTime time.Duration)

DelOld removes old cache items

func (*CacheMap[K, V]) Expire

func (cache *CacheMap[K, V]) Expire(exp time.Duration) bool

Expire sets the ttl for all cache items

func (*CacheMap[K, V]) ForEach

func (cache *CacheMap[K, V]) ForEach(cb func(key K, value V) bool, touch ...bool)

ForEach runs a callback function for each cache item that has not expired

in the callback, return true to continue, and false to break the loop

func (*CacheMap[K, V]) Get

func (cache *CacheMap[K, V]) Get(key K) (V, error)

Get returns a value or an error if it exists

if the object key does not exist, it will return both a nil/zero value (of the relevant type) and nil error

func (*CacheMap[K, V]) Has

func (cache *CacheMap[K, V]) Has(key K) bool

Has returns true if a key value exists and is not an error

func (*CacheMap[K, V]) Set

func (cache *CacheMap[K, V]) Set(key K, value V, err error)

Set sets or adds a new key with either a value, or an error

func (*CacheMap[K, V]) Touch

func (cache *CacheMap[K, V]) Touch(key K) bool

Touch resets a cache items expiration so it will stay in the cache longer

Jump to

Keyboard shortcuts

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