cache

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 5 Imported by: ? 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

func HashKey

func HashKey(prompt string) string

HashKey creates a cache key from a prompt string

Types

type CacheEntry

type CacheEntry struct {
	Value     any
	ExpiresAt time.Time
}

CacheEntry holds a cached value with expiration

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache is a thread-safe LRU cache with TTL support

func NewLRUCache

func NewLRUCache(capacity int, ttl time.Duration) *LRUCache

NewLRUCache creates a new LRU cache with the given capacity and TTL

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear removes all entries from the cache

func (*LRUCache) Dump added in v1.10.5

func (c *LRUCache) Dump() map[string]CacheEntry

Dump returns a slice of cache entries for persistence

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (any, bool)

Get retrieves a value from the cache

func (*LRUCache) Len

func (c *LRUCache) Len() int

Len returns the number of items in the cache

func (*LRUCache) Restore added in v1.10.5

func (c *LRUCache) Restore(dump map[string]CacheEntry)

Restore populates the cache from a map of entries

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value any)

Set adds or updates a value in the cache

Jump to

Keyboard shortcuts

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