Skip to main content

Module cache

Module cache 

Source
Expand description

Mode 2 response cache — in-memory LRU keyed by the 7-input SHA-256 composition from .yah/docs/architecture/mesofact.md §“Cache-key composition”, with the fresh / stale (SWR) / expired state machine from §“Mode 2 caching beyond TTL”.

Invalidation is generation-driven, not purge-driven: each source’s current generation token (sqlite file mtime, r2 Last-Modified, …) is folded into the key (input 6), so a backend bump yields a different key and an automatic miss on the next request — no reverse tag index needed in the hot path.

Structs§

CacheEntry
A cached render result plus the TTL/SWR window it was stored under.
KeyInputs
The ordered inputs to the cache key. Maps are BTreeMap so iteration is already sorted — input 3 (params), 4 (query), 5 (vary), and 6 (source generations) all require deterministic key order.
ResponseCache
Thread-safe LRU response cache. get/insert take &self; the Mutex guards the LruCache (whose get needs &mut to bump recency).

Enums§

CacheState
Freshness verdict for a stored entry at a given instant.

Constants§

DEFAULT_CAPACITY
Default LRU capacity (entries). Tunable via ResponseCache::with_capacity.

Functions§

cache_window
Caching policy by status class (§“Mode 2 caching beyond TTL”): 2xx/3xx cache under ttl+swr; non-2xx (4xx) cache under negative_ttl with no SWR window; 5xx is never cached. Returns (ttl, swr) to store under, or None to skip caching.
compose_key
Compose the SHA-256 cache key as a lowercase hex string. Each field is fed with a label and a record separator so component boundaries can’t collide (e.g. a param value can’t impersonate a query key).