cache

package
v1.12.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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