Persistent server search cache: 200 results per query, 250k queries, 15-day stale-while-revalidate, refresh=1

This commit is contained in:
Claude
2026-10-02 02:10:39 +00:00
parent 14e2307a92
commit c69cc3a4bc
6 changed files with 231 additions and 50 deletions

View File

@@ -112,6 +112,17 @@ export async function initDb() {
CREATE INDEX IF NOT EXISTS idx_media_lru
ON media_cache (status, last_access);
-- Persistent search cache: the YouTube part of a search (up to 200 cards,
-- JSON), keyed by the lowercased query. Trimmed LRU by count and bytes.
CREATE TABLE IF NOT EXISTS search_cache (
q TEXT PRIMARY KEY,
results TEXT NOT NULL,
size INTEGER NOT NULL DEFAULT 0,
fetched_at INTEGER NOT NULL DEFAULT 0,
last_access INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX IF NOT EXISTS idx_search_cache_lru ON search_cache (last_access);
-- Shared per-video documents (kind = lyrics | chapters), visible to every
-- user. The live copy is here; every save also lands in video_note_revs
-- as a full snapshot, which is the server-side backup and undo history.