expiringcache

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpiringCache

type ExpiringCache[KeyType comparable, ValueType any] interface {
	// Get operates identically to retrieving from a map, returning
	// the value and/or boolean indicating if the value existed in the map
	//
	// Multiple callers can receive the same value simultaneously from Get,
	// it is the caller's responsibility to ensure they are not modified
	Get(key KeyType) (value *ValueType, ok bool)
	// Set operates identically to setting a value in a map, adding an entry
	// or overriding the existing value for a given key
	Set(key KeyType, value *ValueType)
}

ExpiringCache is a thread-safe "time expiring" cache that automatically removes objects that are not accessed for a configurable delay

It is used in various places where we need to cache data for an unknown amount of time, to prevent memory leaks

From the consumer's perspective, it behaves similarly to a map KeyType is the type of the object that is used as a key ValueType is the type of the object that is stored.

func New

func New[KeyType comparable, ValueType any](expirationDelay time.Duration) ExpiringCache[KeyType, ValueType]

New returns a new ExpiringCache for a given KeyType, ValueType, and expiration delay.

Jump to

Keyboard shortcuts

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