Invalidate cached policy answers when the evidence or policy scope they depend on changes. A time-to-live alone cannot tell whether an answer is still valid after an immediate policy correction.
Record the dependency before you cache
A cached answer to a returns question depends on more than the wording of the question. Record the source policy revision, region, product scope, prompt or response-generation version, and relevant authorization scope. Without those dependencies, invalidation may become a guess about which answers were affected.
A fresh cache entry can contain old evidence
The fixture stores an answer under policy P1 with an expiration well in the future. The active policy changes to P2. An expiration-only check still accepts the answer, while a dependency check rejects it. These synthetic timestamps illustrate freshness and validity as separate conditions.
Verify the update path
- Update a synthetic policy fact and publish the new source revision.
- Check whether existing response caches and semantic matches are invalidated or rejected by version.
- Test concurrent readers and an in-flight generation started under the previous revision.
- Verify that a rollback deliberately selects its intended policy version rather than inheriting unrelated stale entries.
Avoid unnecessary full-cache deletion
If dependency tracking is trustworthy, invalidate the affected policy scope rather than unrelated stable content. If it is not trustworthy, choose a conservative strategy and document the performance tradeoff. The example does not establish correctness of a distributed invalidation bus or consistency guarantees in your chosen cache.
Run the worked example
Save the synthetic Node.js example and run node invalidate-cached-policy-answers.mjs with Node.js 22 or newer. The assertions check the illustrated records and calculations; they do not test a deployed provider, SDK, or access control. No credentials or network connection are needed.
// Synthetic teaching fixture. No credentials, network calls, or production verification.
import assert from 'node:assert/strict';
const cached = { policyVersion: 'p1', expiresAt: 5000, answer: 'Synthetic policy answer' };
const now = 1000;
const active = { policyVersion: 'p2' };
const ttlValid = cached.expiresAt > now;
const reusable = ttlValid && cached.policyVersion === active.policyVersion;
assert.equal(ttlValid, true);
assert.equal(reusable, false);
assert.equal(ttlValid && cached.policyVersion === 'p1', true);
console.log('TTL is valid, but the policy dependency changed: regenerate the answer.');
References and further reading
Maintained by DriftRail. AI assisted the October 2026 content and template revision. Examples are illustrative; they are not measured product benchmarks. Suggest a correction.