← All packages

@lacspace/llm-cache

v1.0.0LLM Efficiency0 deps

A content-hash cache for LLM calls — key by (model family, prompt version, normalized input) so identical requests, retries after a 429 and repeated rewrites never pay twice. Pluggable async store (in-memory LRU built in, Mongo/Redis/KV via an adapter), TTL, stale-if-error and a wrap() memoizer. Zero-dependency, isomorphic.

npm i @lacspace/llm-cache

Usage

llm-cache.ts
import { createLlmCache, memoryStore } from "@lacspace/llm-cache";

const cache = createLlmCache({ store: memoryStore(), ttlMs: 86_400_000, promptVersion: "v3" });

const pack = await cache.wrap(
  { input: condensedSources, model: "gemini", variant: { lang: "ne" } },
  () => callGemini(condensedSources),   // only runs on a miss
  { staleIfError: true },               // 429? serve the last good result
);
cache.stats(); // { hits, misses, sets }

Exports 3

createLlmCachememoryStorecontentHash

Keywords

llm-cachecachememoizecontent-hashprompt-cachettllrurate-limit429openai

More in LLM Efficiency