cache

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, U comparable, V any] interface {
	// Set inserts or replaces an entry. userID is used for bulk invalidation.
	Set(key K, user U, value V, expiry time.Time)

	// Get returns the cached value if present and not expired, updating its access time.
	Get(key K) (V, bool)

	// Delete removes a single entry by key.
	Delete(key K)

	// DeleteByUser removes all entries associated with the given user ID.
	DeleteByUser(user U)

	// Prune removes all expired entries, returning the count removed.
	Prune() int

	// Stats returns a snapshot of cache statistics.
	Stats() CacheStats
}

Cache is a generic in-memory LRU cache with per-entry expiry and user-based invalidation.

func New

func New[K comparable, U comparable, V any](maxSize int) Cache[K, U, V]

type CacheStats

type CacheStats struct {
	Hits        int64
	Misses      int64
	Evictions   int64 // LRU pressure evictions (max size exceeded)
	Expirations int64 // TTL-based removals via Prune or lazy on Get
	Size        int   // current entry count
}

Jump to

Keyboard shortcuts

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