Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoopLoaderFunc ¶ added in v1.5.0
func NoopLoaderFunc[K comparable, V any](key K) (V, error)
Function that can be used inside a testing environment
Types ¶
type Cache ¶
type Cache[K comparable, V any] interface { // Get an item from the cache. Get(key K) (V, bool) // Put an item into cache. Put(key K, value V) // Returns true when the item exist in cache. Has(key K) bool // Returns true if the cache is empty. IsEmpty() bool // Returns the total count of cached items. Count() int // Loop over each entry in the cache. ForEach(func(key K, value V)) // Deletes an item from the cache. Delete(key K) // Clear all items from cache. Clear() // Cleanup resources and timers. Close() }
type LoaderFunc ¶
type LoaderFunc[K comparable, V any] func(key K) (V, error)
Function that gets executed by the 'Load' and 'Reload' function
type LoadingCache ¶ added in v1.5.0
type LoadingCache[K comparable, V any] interface { // Loads an item into cache using the provided LoaderFunc and returns the value. // // If the item is already cached, it'll return that value instead. // // Whenever the LoaderFunc returns an error, the value does NOT get saved. // // This function is thread-safe and the LoaderFunc is called only once in a concurrent environment. Load(key K) (V, error) // Reloads an item into cache using the provided LoaderFunc and returns the new value. // // Whenever the LoaderFunc returns an error, the value does NOT get saved (old value remains in cache) Reload(key K) (V, error) // Embed Cache Cache[K, V] }
func NewLoadingCache ¶ added in v1.5.0
func NewLoadingCache[K comparable, V any]( loaderFunc LoaderFunc[K, V], options ...Option[K, V], ) LoadingCache[K, V]
type Option ¶
type Option[K comparable, V any] func(c *cache[K, V])
func WithExpireAfterWrite ¶
func WithExpireAfterWrite[K comparable, V any]( expireAfterWrite time.Duration, ) Option[K, V]
The 'TTL' after it has been written to the cache.
Click to show internal directories.
Click to hide internal directories.