cache

package
v0.4.19 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cache provides a cache implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMaxSize is returned when the given max size is not positive.
	ErrInvalidMaxSize = errors.New("max size must be > 0")
)

Functions

This section is empty.

Types

type LRUExpireCache

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

LRUExpireCache is a cache that ensures the mostly recently accessed keys are returned with a ttl beyond which keys are forcibly expired.

func NewLRUExpireCache

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

NewLRUExpireCache creates an expiring cache with the given size

func (*LRUExpireCache[K, V]) Add

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

Add adds the value to the cache at key with the specified maximum duration.

func (*LRUExpireCache[K, V]) Get

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

Get returns the value at the specified key from the cache if it exists and is not expired, or returns false.

Jump to

Keyboard shortcuts

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