module
LLM::Cache
Defined in:
llm/cache.crConstant Summary
-
CACHE_FILE_SUFFIX =
".json" -
All cache entries are stored as
<sha256>.jsonflat in.cache_dir. The bulk operations below (.clear,.purge_older_than,.stats) filter on this suffix so a stray.tmp,.lock, or user-dropped file in the directory is left alone.
Class Method Summary
- .cache_dir : String
- .clear : DeleteOutcome
- .delete(key : String) : Bool
- .disable : Nil
- .disabled_by_env? : Bool
- .enable : Nil
- .enabled? : Bool
- .ensure_dir : Nil
- .fetch(key : String) : String | Nil
-
.key(provider : String, model : String, kind : String, format : String, payload : String) : String
Build a deterministic cache key from inputs
- .path_for(key : String) : String
- .purge_older_than(days : Int32) : DeleteOutcome
- .stats : Stats
-
.store(key : String, content : String) : Bool
Write atomically: a partially-written file from a crash mid-write would parse as broken JSON on the next
.fetch, forcing a spurious fresh API call.
Class Method Detail
Build a deterministic cache key from inputs
- provider: "openai", "ollama", url, etc.
- model: "gpt-4o", "llama3", etc.
- kind: logical operation e.g. "FILTER", "ANALYZE", "BUNDLE_ANALYZE"
- format: response_format string (e.g., "json" or JSON schema string)
- payload: variable content (file list, source code, bundle, etc.)
Returns a hex-encoded SHA256 digest.
Write atomically: a partially-written file from a crash mid-write
would parse as broken JSON on the next .fetch, forcing a
spurious fresh API call. By writing to a tmp sibling and renaming
we either leave the previous (valid) entry in place or atomically
publish the new one.