cache

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cache provides caching primitives for Hanzo Base, built on github.com/luxfi/cache. It re-exports the Cacher interface and LRU implementation, and adds a TTL wrapper for time-based expiration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Empty

func Empty[K comparable, V any]() *lrucache.Empty[K, V]

Empty returns a no-op cache that stores nothing.

func NewLRU

func NewLRU[K comparable, V any](size int) *lrucache.LRU[K, V]

NewLRU creates a bounded LRU cache. Thread-safe.

Types

type Cacher

type Cacher[K comparable, V any] = lrucache.Cacher[K, V]

Cacher is the cache interface from luxfi/cache.

type TTL

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

TTL wraps a Cacher and adds time-based expiration. Entries older than the configured TTL are evicted lazily on Get. Put resets the TTL.

The underlying cache controls eviction policy (e.g. LRU) and size bounds. TTL only adds the time dimension.

func NewTTL

func NewTTL[K comparable, V any](size int, ttl time.Duration) *TTL[K, V]

NewTTL creates a TTL-aware LRU cache with the given max size and TTL.

func (*TTL[K, V]) Evict

func (c *TTL[K, V]) Evict(key K)

Evict removes a specific key.

func (*TTL[K, V]) Flush

func (c *TTL[K, V]) Flush()

Flush removes all entries.

func (*TTL[K, V]) Get

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

Get returns the value if it exists and has not expired. Expired entries are evicted immediately.

func (*TTL[K, V]) Len

func (c *TTL[K, V]) Len() int

Len returns the number of entries (including expired ones not yet evicted).

func (*TTL[K, V]) PortionFilled

func (c *TTL[K, V]) PortionFilled() float64

PortionFilled returns the fraction of the underlying cache that is occupied.

func (*TTL[K, V]) Put

func (c *TTL[K, V]) Put(key K, value V)

Put inserts a value with the current TTL.

Jump to

Keyboard shortcuts

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