cache

package
v0.8.17 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 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 Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a generic lru cache that allows you to lookup values using a key and a version. By design, this cache allows access to only a single version of a given key. A version mismatch is considered a cache miss and the key gets evicted if it exists. When a key is evicted a optional cleanup function is called.

func Must

func Must[T any](size int, cleanup cleanupFunc[T]) *Cache[T]

Must creates a new lru cache with the desired size and cleanup func This function panics if a error occurrs.

func New

func New[T any](size int, cleanup cleanupFunc[T]) (*Cache[T], error)

New constructs a new lru cache with the desired size and cleanup func.

func (*Cache[T]) Add

func (c *Cache[T]) Add(version string, key Key, client T)

Add adds a new value for the given key/version.

func (*Cache[T]) Contains

func (c *Cache[T]) Contains(key Key) bool

Contains returns true if a value with the given key exists.

func (*Cache[T]) Get

func (c *Cache[T]) Get(version string, key Key) (T, bool)

Get retrieves the desired value using the key and compares the version. If there is a mismatch it is considered a cache miss and the existing key is purged.

type Key

type Key struct {
	Name      string
	Namespace string
	Kind      string
}

Key is the cache lookup key.

Jump to

Keyboard shortcuts

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