Documentation
¶
Overview ¶
Package cache provides a Starlark module offering bounded, in-memory key-value caches with TTL expiry.
Design summary (the README's "Design & semantics" section is the long form):
- Namespacing: each new_cache() is an INDEPENDENT instance. There is no central Manager/registry — to separate namespaces, create separate caches.
- Eviction is FIFO (oldest-inserted evicted first), NOT LRU. FIFO needs no per-access bookkeeping, so it is simple and predictable; the tradeoff is that a frequently read ("hot") key is not protected from eviction.
- The bound is max_entries (default 128, host-configurable). Caches never hold more live entries than that.
- Values are stored as an immutable serial snapshot (serial.dumps -> string on set, serial.loads -> fresh value on get), so a cached value is a lossless, independent copy: mutating what you put in, or what you get out, never affects the stored entry. Only serializable values can be cached; a non-serializable value makes set() return an error — there is no silent variant, and no path panics the host.
- Concurrency: every operation is guarded by a sync.Mutex, so reads and writes are serializable and each call sees a consistent snapshot.
- TTL expiry is lazy: an entry is purged on per-key access (get/has/delete) and on keys()/size() scans, never by a background goroutine. The clock is injectable via NewModuleWithClock for deterministic TTL testing.
Index ¶
Constants ¶
View Source
const ModuleName = "cache"
ModuleName is the name used in Starlark's load() for this module.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module wraps a ConfigurableModule with cache-specific functions.
func NewModuleWithClock ¶
NewModuleWithClock creates a Module with an injected clock (for deterministic TTL testing). clock must be non-nil.
func (*Module) LoadModule ¶
func (m *Module) LoadModule() starlet.ModuleLoader
LoadModule returns the Starlark module loader.
Click to show internal directories.
Click to hide internal directories.