Documentation
¶
Overview ¶
Package cache provides a simple, concurrent-safe in-memory cache with expiration support.
Package cache provides a simple, concurrent-safe in-memory cache with expiration support.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores arbitrary data with expiration time.
func New ¶
New creates a new cache that asynchronously cleans expired entries after the given time passes.
func (*Cache) DeleteExpired ¶
func (cache *Cache) DeleteExpired()
type GenericCache ¶ added in v1.0.1
type GenericCache[K comparable, V any] struct { // contains filtered or unexported fields }
GenericCache stores arbitrary data with expiration time.
func NewGeneric ¶ added in v1.0.1
func NewGeneric[K comparable, V any](defaultDuration time.Duration) *GenericCache[K, V]
NewGeneric creates a new cache that asynchronously cleans expired entries after the given time passes.
func (*GenericCache[K, V]) Delete ¶ added in v1.0.1
func (cache *GenericCache[K, V]) Delete(key K)
Delete deletes the key and its value from the cache.
func (*GenericCache[K, V]) DeleteExpired ¶ added in v1.0.1
func (cache *GenericCache[K, V]) DeleteExpired()
DeleteExpired deletes all expired items from the cache.
func (*GenericCache[K, V]) Get ¶ added in v1.0.1
func (cache *GenericCache[K, V]) Get(key K) (V, bool)
Get gets the value for the given key.
func (*GenericCache[K, V]) Set ¶ added in v1.0.1
func (cache *GenericCache[K, V]) Set(key K, value V, duration time.Duration)
Set sets a value for the given key with an expiration duration. If the duration is less than 0, it will be stored forever. If the duration is 0, the default expiration time will be used