Skip to main content

Module store

Module store 

Source
Expand description

CacheStore — in-memory LRU + redb disk-backed cache.

§Architecture

  get(key)
    │
    ├─ validation gate: profile_validation_ts == None? → Ok(None)
    │
    ├─ in-memory map hit? → deserialise + classify freshness → return
    │
    └─ redb table hit?   → populate in-memory + classify freshness → return

put writes to both layers. invalidate removes from both layers. invalidate_profile removes every key whose profile prefix matches.

§Disk schema

One redb table named "cache".

  • Key : serialized CacheKey bytes (CacheKey::serialize_key()).
  • Value: serde_json::to_vec(CacheEntry<serde_json::Value>).

§Clock injection

CacheStore::new_with_clock accepts a Clock impl so tests can control time without sleeping. Production code uses SystemClock.

Structs§

CacheStore
In-memory + disk-backed authoritative cache.
InMemoryEntry 🔒
An in-memory slot holds the raw JSON bytes so the type parameter can vary per call site without making CacheStore itself generic.
MockClock
Controllable test clock.
SystemClock
Real wall-clock implementation.

Constants§

CACHE_TABLE 🔒
Single table: serialized CacheKey → JSON-encoded CacheEntry<Value>.

Traits§

Clock
Source of the current Unix timestamp in seconds.

Functions§

open_or_recreate_redb
Open a redb Database at path, recreating the file when it has a stale on-disk schema.
open_redb_or_in_memory
Open a redb Database, returning an in-memory backend as the final fallback so callers never have to panic during app startup.

Type Aliases§

CacheHandle
Shared cache handle. Clone to share across threads.