ttlcache

package
v0.3.307 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ttlcache provides passive, fixed-TTL LRU caches. It starts no goroutines and registers no asynchronous callbacks. This evaluation adapter is not used by production caches: synchronous expiration failed the latency gate.

Reads update LRU order without extending expiration. Expired entries are immediately unreadable, but their references remain until a write, Len, DeleteAll, or disposal. Finite capacities bound stored entry count; unlimited caches do not have a memory bound.

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 is an experimental passive cache retained for migration benchmarks.

func New

func New[K comparable, V any](capacity int, ttl time.Duration) *Cache[K, V]

New creates a cache. Nonpositive capacity means unlimited; nonpositive TTL means no expiration, replacing expirable's ten-year sentinel.

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key K)

Delete removes a key, if present.

func (*Cache[K, V]) DeleteAll

func (c *Cache[K, V]) DeleteAll()

DeleteAll removes all retained entries.

func (*Cache[K, V]) Get

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

Get returns a live value and promotes its LRU position without renewing TTL.

func (*Cache[K, V]) Has

func (c *Cache[K, V]) Has(key K) bool

Has rejects expired entries without updating LRU order or expiration. Unlike expirable.Contains, it does not recognize retained expired entries.

func (*Cache[K, V]) Len

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

Len reclaims expired entries and reports live entries, rather than counting retained expired entries as expirable.Len does.

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, value V)

Set renews expiration and reclaims expired entries before capacity eviction. Reclamation synchronously holds the cache lock for the full expired batch; this failed the latency gate and must not be used on production hot paths.

Jump to

Keyboard shortcuts

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