Cache invalidation and freshness for LLM answers

Who wrote Hamlet and today's stock price cannot share a TTL. The ways to keep cached LLM answers fresh: TTL, stale reads, source purge, purge by meaning.

Cache invalidation for LLM answers is how you stop a cached answer being served after the fact behind it has changed. No single lifetime fits: who wrote Hamlet stays true for centuries, a stock price for seconds. A working setup combines a time to live per answer, purges tied to the source of the answer, and purges by meaning.

Why can't every cached answer share one TTL?

Pick one time to live for the whole cache and you are wrong for most of it. Set it long and you serve last week's price as today's. Set it short and you pay the model to work out again that Shakespeare wrote Hamlet.

HTTP caching has precise words for this. In RFC 9111, a response is fresh while its age has not exceeded its freshness lifetime, and stale after that. On the web, the origin server usually states the lifetime. An LLM answer has no origin server. The model does not tell you how long its answer stays true, so the lifetime has to come from somewhere else: you, the source document, or a second model.

What are the ways to keep an LLM cache fresh?

Freshness mechanisms and the Crowkis command for each
MechanismUse it when you knowCommand
Time to liveRoughly how long the answer stays trueCSET … EX secs
Stale readA slightly old answer is fine while you refreshCSTALE
Source lineageWhich document or record the answer was built onCSOURCE LINK, CSOURCE PURGE
Purge by meaningA topic changed, and you can describe itCINVALIDATE
NoticeSomething changed today, in one sentenceCNOTICE ADD
Model-judged lifetimeNothing in advanceThe opt-in decision engine
FlushEverything for a tenant has to goCFLUSH TENANT t

They combine. Time to live covers what you cannot know. Lineage and purges cover what you can.

How long should a cached LLM answer live?

text
CSET "Who wrote Hamlet?" "William Shakespeare." EX 31536000 TENANT acme
CSET "What is the order cutoff today?" "Orders placed before 3pm ship today." EX 3600 TENANT acme

EX on CSET sets the lifetime in seconds for that entry, and a namespace can carry a default for writes that do not set one. Be clear about one thing: the lifetime does not vary by the type of question by itself. A table of lifetimes per query type exists in the storage layer, but nothing references it. Either your application sets EX, or you let a model do it.

Letting a model do it is the decision engine, which is off by default. After CSET stores an answer, your own model is asked in the background how long the answer stays correct. Reads are never slowed. The model sorts each answer into one of four classes.

Decision engine lifetime classes and their defaults
ClassDefault lifetimeOur example of the kind
permanent1 yearWho wrote Hamlet
slow30 daysHow a product feature works
operational1 hourToday's opening hours
live5 minutesA price or a status

The four defaults are set in seconds through CROWKIS_DECIDE_TTL_PERMANENT, _SLOW, _OPERATIONAL and _LIVE. While the engine is on, an answer is held back from every read until the model has vouched for it, and CDECISION query shows the lifetime and ttl it was given. The cost is one small model call per judged answer, and the text, after PII redaction, is sent to the endpoint you configure.

What is stale-while-revalidate, and does it fit LLM answers?

A hard expiry is a blunt tool. The moment an entry passes its lifetime, the next user waits for a full model call, even if the answer is one second out of date and perfectly usable. The web solved this with stale-while-revalidate, which lets a cache immediately return a stale response while it revalidates it in the background.

text
CSTALE "What is the order cutoff today?" TENANT acme

CSTALE query [TENANT t] returns the cached answer even when it is past its lifetime, with a stale flag and the remaining lifetime. It returns null when no entry exists, or while the decision engine is holding the answer back. Crowkis does not run the refresh for you. The flag is the signal, and the refresh is your code:

  1. Call CSTALE. If the reply is not stale, serve it.
  2. If it is stale and the question can tolerate that, serve it now and start a model call in the background.
  3. When the model replies, write the new answer with CSET and a fresh EX.
  4. If it is stale and the question cannot tolerate that, such as a price or a balance, wait for the model instead.

That is the fit for LLM answers: a chat reply or a summary can be a little old, and a number someone will act on cannot.

How do you invalidate answers when the source document changes?

Most cached answers are derived from something: a help article, a pricing page, a database record. When that source changes, every answer built on it is wrong at once, and a timer cannot know. This is the usual case for answers generated from retrieved documents, as in self-hosted RAG with CDOC. Lineage ties answers to their source so they can be removed together.

text
CSOURCE LINK pricing-doc "How much is the pro plan?" TENANT acme
CSOURCE LIST pricing-doc TENANT acme
CSOURCE PURGE pricing-doc TENANT acme
  • CSOURCE LINK source_id query ties a cache entry to a source id of your choosing.
  • CSOURCE LIST source_id shows what is linked to that source.
  • CSOURCE PURGE source_id removes every linked entry in one cascade. Links are persistent and scoped to the tenant.

CDN users will recognise the pattern. Cloudflare's cache-tag purging works the same way: tag assets when you serve them, then purge by tag. Wire CSOURCE PURGE into whatever publishes the document, such as a CMS hook or a deploy job.

Call the command, not the webhook. POST /api/v1/invalidate records the request, returns accepted: true and purges nothing. PUT /api/v1/version/:source_id stores a version record that no read path consults. The Crowkis docs list both as inert.

How do you purge by meaning?

Sometimes there is no source id, only a description: everything about the old pricing, anything that mentions the discontinued plan. CINVALIDATE takes that description in plain English.

text
CINVALIDATE "answers about the old pricing" TENANT acme LIMIT 50
CINVALIDATE "answers about the old pricing" TENANT acme LIMIT 50 COMMIT

CINVALIDATE instruction [TENANT t] [THRESHOLD f] [LIMIT n] [COMMIT] previews by default. The first line lists what would be purged and deletes nothing. Only COMMIT purges. Matching by meaning is easy to get slightly wrong, so read the preview, tighten THRESHOLD until the list is the set you meant, then commit.

CNOTICE is for the operational case, where something is different today and you want to say so in a sentence.

text
CNOTICE ADD "We close at 3pm today" PREVIEW TENANT acme
CNOTICE ADD "We close at 3pm today" TENANT acme
CNOTICE LIST TENANT acme
  • ADD looks at up to 32 cached answers within similarity 0.30 of the notice.
  • Without the decision engine, answers at similarity 0.55 or above are removed before the reply.
  • With the engine on, all of them stop being served at once. Its model then removes the ones the notice makes wrong and puts the rest back, usually within seconds. One still unchecked after 10 minutes expires.
  • PREVIEW reports matched without removing anything, and truncated tells you that more answers were near than were looked at.
  • A tenant can have at most 8 active notices, of 512 bytes each.

What does not work yet?

  • Webhook purge. As above, the HTTP invalidate endpoint purges nothing.
  • Lifetime by query type. The policy table has no callers. Lifetime never varies by query type unless you or the decision engine set it.
  • Version-aware recompute. The stored version record is not read by any lookup.
  • Freshness decay by domain. Freshness is one of the signals in the confidence score, but every entry decays at the general rate. A regulatory answer decays exactly as quickly as a historical fact. See false positives and confidence scoring.
  • Automatic refresh. CSTALE flags a stale answer. It does not regenerate it.
  • Links from before 0.5.2. Source links are now scoped to the tenant, so links written by an earlier version must be created again before a purge can find them.

Common questions

What TTL should I use for LLM answers?

Match it to the fact, not the cache. As a starting point, borrow the decision engine's four classes: a year for timeless facts, a month for slow-moving product knowledge, an hour for operational details and minutes for live values. Then shorten anything a user would act on.

Does changing the model invalidate the cache?

CSET and CGET both take MODEL and MODEL_VERSION, so an entry records which model wrote it and a read can ask for a specific one. Changing the embedding model is different: entries embedded by another model are refused on read, so the cache warms again once. Local embeddings with CEMBED covers the embedder.

Is a short TTL enough without invalidation?

Only for answers where being wrong for the length of the TTL is acceptable. A short lifetime also throws away reuse on answers that never change, which is the saving a cache exists for. Use lineage for answers with a known source and keep TTL as the backstop.

How do I see why an answer is still being served?

CSTALE shows the remaining lifetime, CSOURCE LIST shows what a source is linked to, and CDECISION shows the decision engine's verdict. The command reference and the Crowkis docs list the options, and cache eviction for LLM answers covers what leaves the cache and when.

Filed under Features. Published .

Book your demo today.

A 30 minute call. Bring your stack and your questions.

Pick a time

Or write to us.