Fixing stale cached AI responses with write-time key invalidation

AI-200 By islever Editorial Last updated

Integrate Azure Managed Redis in AI solutions Develop AI solutions by using Azure Cosmos DB for NoSQL

Short answer

C Invalidating affected cache keys when source records change, so the next cache-aside read misses and reloads current data from the authoritative database.

Question

Source records change before their cached copies expire, causing stale AI responses. The source database must remain authoritative. Which cache-aside change directly addresses the problem?
  1. Increase every cache entry's time to live.
  2. Treat the cached response as the system of record.
  3. Invalidate affected keys when source records change. Correct Answer
  4. Allow all clients to recompute a missing value concurrently.

Key Takeaways

Stale AI responses in a cache-aside design are fixed by invalidating affected keys whenever the authoritative source record changes, forcing the next read to miss and reload current data. Increasing time to live prolongs staleness, and promoting the cache to system of record destroys the authority the database must keep. Explicit write-time invalidation is the only option that closes the freshness gap without changing ownership.

Expert Analysis

Because the source database must stay authoritative while cached copies are allowed to expire on their own schedule, the only cache-aside change that removes the stale window is explicit key invalidation at write time — option C. The condition that would make an alternative genuinely correct is worth stating precisely, because cache-aside failures are usually ownership failures or timing failures rather than missing features.

Extending TTL only widens the window in which "Increase every cache entry's time to live" stays wrong

Option A would become the right answer only if the underlying data were naturally immutable within its retention horizon — reference data such as country codes, currency tables or product catalogues that genuinely do not change for days. Under that premise, a longer time to live reduces reload pressure without any correctness cost, and TTL tuning becomes a legitimate design lever. That premise fails here: the failure being reported is that source records change before the cached copies expire, so the cache is already holding values that no longer match the system of record. Raising the time to live moves the expiry boundary further into the future, which lengthens, rather than shortens, the period during which a retrieval-augmented or model-backed response is assembled from obsolete data. TTL is a bounded-staleness mechanism, not a correctness mechanism; it bounds how long you tolerate drift, and here the tolerance itself is the defect. Option A therefore treats the symptom's clock instead of its cause.

Write-time invalidation converts a source mutation into a guaranteed cache miss

The decisive property of this design is that the source database remains the single authority, and cache-aside reads are only ever a shortcut in front of it. Option C preserves that ordering by coupling the two stores at the moment of change: when a source record is updated or deleted, the code path that performs the write also removes the corresponding key, so the next read misses, falls through to the database, and repopulates the entry with the current value. This is the standard invalidation half of the cache-aside pattern, and it is what makes "the cache may be wrong for a while" collapse into "the cache is wrong only between the write and the delete". The key detail is which keys: an entry keyed on a query, a document ID, or a prompt-plus-context tuple must be invalidated on the same identity the read path uses, otherwise the delete hits a key nobody reads and the stale entry survives untouched.

Each remaining option trades away authority, availability or consistency inside this design

Option B breaks the ownership rule outright, since promoting the cached response to system of record means there is no longer an authoritative database against which staleness could even be detected, and every downstream AI answer inherits whatever drifted value happened to be cached; option D, letting all clients recompute a missing value concurrently, is the cache stampede, and it attacks availability rather than freshness — after an invalidation, a burst of simultaneous misses is exactly the traffic shape this option permits, so the stale-data fix would be paid for with throttled or exhausted backend capacity unless a lock, single-flight or early-recomputation guard is added, and invalidation alone never causes stale reads so it introduces no correctness risk of its own. The distinction matters: A is a freshness mistake, B is an authority mistake, D is a concurrency mistake, and only C is a freshness fix that leaves authority and availability intact.

Invalidation lands on the write path, which is where the cache-aside contract is enforced

The mechanism has two halves and the fix sits in the second. The read half says: attempt the cache by key, and on a miss load from the source and populate with a TTL. The write half says: commit to the source first, then evict the affected key — and eviction is preferred over updating in place, because a blind write into the cache can race with a concurrent reader that repopulates from a pre-commit snapshot. Ordering carries real weight: delete after the source transaction commits, not before, or a reader between the delete and the commit will refill the entry with the old row and the correction is lost. Cross-instance caches such as Azure Managed Redis need the eviction to reach the shared store rather than a process-local dictionary, and short TTLs remain as a backstop for evictions missed by a failed or out-of-band change. Invalidation takes effect precisely at that post-commit eviction step.

Official Reference

Exam Strategy

When a caching question states which store is authoritative, eliminate every option that reassigns that role or moves the expiry clock — those change ownership or tolerance, not correctness. Look instead for the option that couples the cache to the write path of the source, then confirm it names the same key identity the read path uses. If a distractor mentions concurrent recalculation, recognize it as a stampede/availability concern and keep looking for the freshness mechanism.

Practice All AI-200 Questions

Access 69 questions with complete answers and detailed explanations.

View Full AI-200 Practice Test →

← Back to AI-200 Study Guide