cache

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRUExpireCache added in v1.0.0

type LRUExpireCache[K comparable, T any] struct {
	// contains filtered or unexported fields
}

LRUExpireCache is a drop in replacement for the apimachinery version that makes it typed with generics, and also data immutable via deep copies.

func NewLRUExpireCache added in v1.0.0

func NewLRUExpireCache[K comparable, T any](maxSize int) *LRUExpireCache[K, T]

func (*LRUExpireCache[K, T]) Add added in v1.0.0

func (c *LRUExpireCache[K, T]) Add(key K, value T, ttl time.Duration)

func (*LRUExpireCache[K, T]) Get added in v1.0.0

func (c *LRUExpireCache[K, T]) Get(key K) (T, bool)

type TimeoutCache

type TimeoutCache[V any] struct {
	// contains filtered or unexported fields
}

TimeoutCache provides a cache with timeout.

func New

func New[V any](refresh time.Duration) *TimeoutCache[V]

New gets a new cache.

func NewWithClock added in v1.11.0

func NewWithClock[V any](refresh time.Duration, c clock) *TimeoutCache[V]

func (*TimeoutCache[V]) Get

func (m *TimeoutCache[V]) Get() (value V, ok bool)

Get returns the cached value if set and it hasn't timed out and returns true. If it has timed out, it will return V's zero value and false, and will need to be set again.

func (*TimeoutCache[V]) Invalidate added in v1.11.0

func (m *TimeoutCache[V]) Invalidate()

func (*TimeoutCache[V]) Set

func (m *TimeoutCache[V]) Set(value V)

Set remembers the value and resets the invalid time based on when the cache was set.

Jump to

Keyboard shortcuts

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