lru

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package lru implements a LRU based cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[k comparable, v any] struct {
	// contains filtered or unexported fields
}

Cache encapsulates a thread-safe fixed size LRU cache.

func New

func New[k comparable, v any](size int, useCase string) (*Cache[k, v], error)

New returns a new LRU cache that can hold 'size' number of keys at a time.

func NewWithEvict added in v0.74.0

func NewWithEvict[k comparable, v any](size int, useCase string, onEvict func(k, v)) (*Cache[k, v], error)

NewWithEvict returns a new LRU cache that can hold 'size' number of keys at a time.

func (*Cache[k, v]) Get

func (c *Cache[k, v]) Get(ctx context.Context, key k) (interface{}, bool, error)

Get executes a lookup and returns whether a key exists in the cache along with its value.

func (*Cache[k, v]) Purge

func (c *Cache[k, v]) Purge(_ context.Context) error

Purge evicts all keys present in the cache.

func (*Cache[k, v]) Remove

func (c *Cache[k, v]) Remove(_ context.Context, key k) error

Remove evicts a specific key from the cache.

func (*Cache[k, v]) Set

func (c *Cache[k, v]) Set(_ context.Context, key k, value v) error

Set registers a key-value pair to the cache.

Jump to

Keyboard shortcuts

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