Principle:AIScientists Dev WorldSeed Result Caching
| Knowledge Sources | |
|---|---|
| Domains | Persistence, Caching |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
A file-based caching strategy that stores LLM-generated gazette results as timestamped JSON files per run, enabling multiple gazettes per run, newest-first listing, and legacy migration — without requiring a database.
Description
The `GazetteCache` stores gazette results in `~/.worldseed/runs/{run_id}/gazettes/{gazette_id}.json`. The `gazette_id` is a timestamp-based identifier (`YYYYMMDD_HHMMSS`), so files sort naturally newest-first by filename.
Operations:
- save: Writes a `GazetteResult` (content + generation metadata) as JSON, returns the gazette_id
- get_gazette: Reads a specific gazette by ID, deserializes to `GazetteResult`
- list_gazettes: Lists all gazettes for a run (summary only: id, edition_title, language, model, cost, created_at), sorted newest-first
- get_latest: Reads the most recent gazette
Legacy migration: Old runs stored a single `gazette.json` at the run root. The cache auto-migrates this to the `gazettes/` directory format on first access.
The `GazetteResult` Pydantic model bundles: `run_id`, `scene_id`, `language`, `generation` metadata (model, elapsed, tokens, cost), `gazette` content (edition_title, breaking_banner, lead_story, secondary_stories, editorials, ticker, pull_quote), and `agents` profiles.
Usage
Use this principle to cache and retrieve gazette results. The gazette API uses this to persist generated content and serve cached results to the frontend.
Theoretical Basis
The cache follows a timestamp-keyed file store pattern:
# Abstract pattern (NOT real implementation)
def save(run_id, result):
gazette_id = datetime.now().strftime("%Y%m%d_%H%M%S")
path = gazettes_dir(run_id) / f"{gazette_id}.json"
path.write_text(json.dumps(result.model_dump()))
return gazette_id
def list_gazettes(run_id):
files = sorted(gazettes_dir(run_id).iterdir(), reverse=True)
return [extract_summary(f) for f in files if f.suffix == ".json"]
Timestamp-based IDs provide natural ordering and uniqueness without a counter or database.