Skip to main content

Module cache

Module cache 

Source
Expand description

Redis-backed pagination cache for list commands.

FicHub shares its Redis instance with the bot. When a user runs /recs, /search, /ask, /quote, or /requests, the full result list is stored under a short-lived session key; !next/!prev/!page X then read from Redis instead of re-calling the API (no DB hammering).

Key layout: archivist:session:<user_id>:<session_id> → JSON array of PageEntry (the whole list, so pagination is trivial).

Response cache: archivist:askcache:<sha256(q)> → JSON AskResponse, and archivist:searchcache:<sha256(qs)> → JSON SearchResponse. These protect the public bot from hammering the LLM (/ask) and the API (/search). Only Ok responses are cached; a Redis failure never blocks the request (best-effort, like log_search).

Structs§

PageCache
Redis-backed cache for paginated lists.
PageEntry
A single paginated-list entry: the raw item plus a stable ordering index.
PageList
A paginated list session stored in Redis.
SearchLogEntry
One search-log row: everything needed to reproduce/debug a search request.

Constants§

ASK_CACHE_TTL_SECS
How long cached /ask responses live (LLM generation is expensive — a popular public bot would otherwise hammer Ollama with identical queries).
SEARCH_CACHE_TTL_SECS
How long successful /search responses live (cheap, but rate-limits / transient API errors should not force a re-fetch for every caller).
SEARCH_LOG_CAP
Max entries kept per day in the search log.

Functions§

page_count
Number of pages for a list.
slice_page
Pagination helper: slice a list for a given page.