# Cache Invalidation

Cache invalidation is the process of making cached data unusable or requiring it to be checked again when it may no longer match the authoritative source.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/cache-invalidation

> Caches reduce latency, backend load, and cost, but cached copies can become outdated when source data, application logic, or access permissions change. Invalidation defines when those copies must expire, be removed, or be replaced so that performance improvements do not violate freshness, correctness, or security requirements.

Practice exams covering Cache Invalidation: [ANS-C01 AWS Certified Advanced Networking - Specialty](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty), [SOA-C03 AWS Certified CloudOps Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate), [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional), [SAA-C03 AWS Certified Solutions Architect - Associate](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate), [SAP-C03 AWS Certified Solutions Architect - Professional](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional).

## 6 key aspects of Cache Invalidation

Effective invalidation combines explicit freshness targets, correct cache identities, dependable change handling, and controlled refill behavior.

1. **Explicit freshness requirements**: Define acceptable staleness for each data class before selecting a TTL or invalidation mechanism. Bypass caches or validate against the authoritative source when stale values would violate security or transactional requirements.
2. **Expiration, invalidation, and versioning**: Use expiration to limit reuse over time, explicit invalidation to react to changes, and versioned keys to separate old and new representations. These mechanisms can work together rather than being mutually exclusive.
3. **Correct cache identity and dependency tracking**: Include every input that materially changes a response in its cache identity, while excluding irrelevant inputs that fragment the cache. Track dependencies so that changes invalidate derived results as well as individual records.
4. **Concurrency and distributed propagation**: Expect delays and races between source updates, invalidation delivery, and cache repopulation. Use version checks, reliable event processing, and idempotent invalidation handlers where stronger guarantees are needed.
5. **Controlled cache refill**: Protect origins and databases when entries expire or are invalidated. Request coalescing, TTL jitter, and carefully scoped invalidations reduce synchronized misses and unnecessary recomputation.
6. **Context-aware AI reuse**: Scope cached answers by authorization, model configuration, prompt version, and source-data version. Treat semantic similarity as a reuse candidate rather than proof that an answer is still correct.

## Cloud services for Cache Invalidation

CloudFront manages cached HTTP content near viewers, while ElastiCache can hold application-level results shared across compute instances. Source updates should trigger the appropriate invalidations independently at each layer; clearing one cache does not clear the others. For generative AI applications, OpenSearch Service can find semantically similar cached answers, while application logic verifies freshness, dependencies, and access rights before reuse. When an answer cannot be reused, the application invokes Bedrock, where supported prompt caching may reduce repeated prefix-processing work. Coordinate cache keys, versions, TTLs, and monitoring across these layers so that performance improvements do not introduce stale or unauthorized responses.

- **[Amazon CloudFront](https://blowstack.com/tools/cloud-services-hub/amazon-cloudfront)**: CloudFront supports path invalidations and configurable cache policies for edge-cached content. Use invalidations to remove outdated objects, and use versioned URLs for routine asset releases; neither approach directly clears existing browser caches.
- **[Amazon ElastiCache](https://blowstack.com/tools/cloud-services-hub/amazon-elasticache)**: Applications using ElastiCache can implement TTLs, key deletion, versioned namespaces, and cache-aside patterns for database results or generated answers. Application logic remains responsible for connecting source changes to the correct cached keys and handling update races.
- **[Amazon Bedrock](https://blowstack.com/tools/cloud-services-hub/amazon-bedrock)**: Bedrock offers prompt caching for supported models, allowing reuse of eligible prompt-prefix processing rather than completed answers. Applications that cache Bedrock outputs separately must define their own result-validity rules and invalidate answers when prompts, models, permissions, or grounding data change.
- **[Amazon OpenSearch Service](https://blowstack.com/tools/cloud-services-hub/amazon-opensearch-service)**: OpenSearch Service can provide vector similarity search for an application-managed semantic answer cache. The application must apply authorization filters, similarity thresholds, expiration rules, and dependency-version checks before reusing a retrieved answer.

## Cache Invalidation exam questions

Real practice exam questions on Cache Invalidation, with the correct answer and its explanation.

### Question 1 (SOA-C03)

**Question:**

A logistics application calls an external service to calculate shipping estimates. To handle traffic spikes without exceeding the external service's request quota, application instances share cached estimates in an Amazon DynamoDB table. Each item contains an estimate and an expiresAt attribute set to 300 seconds after the estimate was generated. DynamoDB Time to Live (TTL) is enabled on expiresAt.

The application uses GetItem and reuses any estimate that DynamoDB returns. Operators discover that estimates are sometimes reused more than 300 seconds after generation, even though the items have valid TTL timestamps. The application must never reuse an estimate after its expiresAt time, but unexpired estimates must remain reusable.

Which change should a CloudOps engineer implement?

**Correct answer:** Check expiresAt before reusing each returned estimate. Treat an expired item as a cache miss, calculate a new estimate, and replace the item with a new expiration timestamp.

**Explanation:** DynamoDB TTL provides asynchronous cleanup, not immediate expiration enforcement for reads. Checking the timestamp in the application prevents reuse of expired estimates while preserving cache hits for unexpired items.

### Question 2 (SAP-C03)

**Question:**

An industrial equipment company runs a reference-data API backed by Amazon Aurora PostgreSQL and an Amazon ElastiCache for Memcached cluster. The database contains specifications for millions of equipment models, but customers request only a small subset. Separate administrative applications update specifications directly in Aurora. Cached specifications can be stale for approximately 60 seconds, but frequently requested specifications must not remain stale indefinitely.

During a maintenance exercise, an empty node replaces a cache node. The API currently returns errors for records that were on the replaced node, even though those records remain available in Aurora. The company requires requests to continue succeeding during cache recovery without waiting for a bulk reload. Recovery must populate the cache only with requested records and restore low-latency access for repeatedly requested records, including records that are never updated. Load testing confirms that Aurora can support the temporary increase in reads during recovery.

Which application design meets these requirements?

**Correct answer:** Read from Memcached first. On a miss, retrieve the record from Aurora, return it, and attempt to cache it with a 60-second TTL. Do not extend the TTL on cache hits. If a cache operation fails, serve the database result without requiring the cache write to succeed.

**Explanation:** This design populates the cache on demand. An empty replacement node causes database reads and temporarily higher latency, rather than application errors. Requested records are cached again, including records that never change. A TTL that is not renewed on hits prevents popular entries from remaining cached indefinitely, and cache write failures do not make the authoritative database unavailable.

### Question 3 (SAA-C03)

**Question:**

A logistics company stores shipment records in Amazon DynamoDB. A dispatch dashboard repeatedly issues identical Query requests to list shipments assigned to each depot. The application uses a DynamoDB Accelerator (DAX) cluster for all reads and writes. Although individual shipment updates succeed, the dashboard sometimes displays an older shipment list for several minutes.

The company accepts eventually consistent results, but requires that a cached Query result be reused for no more than 10 seconds after it is cached. Repeated queries must continue to benefit from caching to reduce DynamoDB read traffic. The company wants to avoid implementing application-managed cache invalidation.

Which change meets these requirements?

**Correct answer:** Set the DAX query cache TTL to 10 seconds.

**Explanation:** DAX caches Query result sets separately from individual items. Writes through DAX do not invalidate cached query results. Setting the query cache TTL to 10 seconds limits their reuse while retaining caching benefits for repeated requests. This controls cache lifetime; it does not make the underlying reads strongly consistent.

### Question 4 (AIP-C01)

**Question:**

A document-review application uses Amazon Bedrock to generate one reusable summary per document. An Amazon DynamoDB table stores each document's current text and monotonically increasing revision in a source item, and its cached summary in a separate item keyed by document ID. Cache lookups use strongly consistent reads in a single AWS Region.

When a document changes, the application uses a DynamoDB transaction to update the source revision and delete the cached summary. However, a generation worker can read revision 12 before an update, finish generating after revision 13 is committed, and then recreate the cache item with the revision 12 summary.

Any cache lookup that begins after a document update commits must not return a summary from an earlier revision. The application must retain caching for unchanged documents and allow generation to proceed concurrently with document updates.

Which change meets these requirements?

**Correct answer:** Publish each generated summary with a DynamoDB transaction that checks whether the source revision still equals the worker's revision and writes the separate cache item. If the condition fails, discard the result and retry against the current revision.

**Explanation:** The source revision check and cache write are atomic. If the document update commits first, the outdated worker's transaction fails. If the worker's transaction commits first, the subsequent document-update transaction deletes its summary. This prevents late generation from undoing invalidation while preserving reuse for unchanged documents.

## Practice Cache Invalidation in a full exam

Questions on Cache Invalidation in each practice exam, with every answer option and an explanation for each:

- [SOA-C03](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate): 9 questions
- [SAP-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional): 4 questions
- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 4 questions
- [SAA-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate): 2 questions
- [ANS-C01](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty): 1 question

## What is Cache Invalidation

Cache invalidation coordinates cached copies with the information they represent. A cache entry might contain a database query result, a web asset, an API response, or a generated answer. Before choosing an invalidation strategy, define how much staleness the application can tolerate. A product description might remain usable for several minutes, while a revoked permission or an inventory reservation may require an authoritative check rather than a cached answer.

Common approaches include time-based expiration, explicit invalidation after a change, and versioned cache keys. A time to live, or TTL, limits how long an entry is normally reusable, but does not detect source changes immediately. Explicit invalidation removes or marks affected entries when a write occurs. Versioned keys make old entries unreachable by directing readers to a new version; the old entries can expire later. Capacity eviction is different: it removes entries to free memory, not because their contents are known to be outdated.

In a cache-aside database application, the application reads the cache first and queries the database on a miss. After committing a database update, it can delete the affected cache entry so that a later read repopulates it. This sequence still has races: a concurrent reader can retrieve old database data and populate the cache after the deletion. Systems with tighter correctness requirements may need version checks, coordinated updates, or authoritative reads. Updating one record can also invalidate multiple derived entries, such as product details, category pages, and aggregate reports.

For content delivery, distinguish the origin, CDN cache, and browser cache. Replacing an origin object does not automatically replace copies already cached elsewhere. A CDN invalidation targets cached paths, whereas a versioned filename such as app.a81c.js lets clients request a distinct object. CloudFront invalidations do not clear browser caches, and propagation is not instantaneous. Use targeted invalidations for corrections and content-hashed filenames for routine immutable-asset deployments.

When troubleshooting CloudFront, inspect the requested URL, selected cache behavior, cache key, response headers, and origin response. Headers such as Age and X-Cache help distinguish cached responses from origin fetches. Check whether query strings, cookies, or headers that change the response are included in the cache key. Missing dimensions can serve the wrong variant; unnecessary dimensions reduce the hit ratio. Review Cache-Control, cache-policy minimum, default, and maximum TTLs, and error caching settings. A positive CloudFront minimum TTL can cause caching even when the origin sends no-cache, no-store, or private. Correct the underlying policy or origin problem before invalidating, or the cache can refill with the same incorrect response.

Caching improves dynamic scalability by absorbing repeated work rather than merely adding application instances. However, invalidating a popular entry can send many simultaneous requests to the database or origin, creating a cache stampede. Request coalescing, refresh-ahead, and randomized TTLs reduce this risk. Serving stale content during refresh can improve availability when the business permits it, but is inappropriate for data requiring strict freshness. Monitor hit ratio, miss latency, backend load, and invalidation failures, not just cache memory usage.

Generative AI caches need validity rules beyond the prompt text. Deterministic request hashing should use a canonical representation of relevant inputs, including model and prompt versions, inference settings, tenant scope, and retrieval context. A result fingerprint can associate an answer with the document or tool-result versions on which it depends. Changes to those dependencies should invalidate the answer or move requests into a new cache namespace. Hashing identifies matching inputs; it does not itself ensure that an answer remains valid.

Semantic caching reuses answers for sufficiently similar requests, so similarity thresholds must be tested against correctness and authorization requirements. A similar question may still require a different answer because of time, user permissions, or changed source documents. Model prompt caching is distinct from answer caching: it reuses processing of supported prompt prefixes and generally still involves a model invocation. Edge caching of generated responses requires the same tenant isolation and freshness controls as other personalized content. Evaluate avoided invocations, cache costs, latency, and incorrect-reuse rates together.

## Learn Cache Invalidation in lessons

5 short lessons on Cache Invalidation in 4 certification courses.

- SOA-C03: Cache Invalidation: removing and replacing stale copies (Premium), https://app.blowstack.com/lessons/cache-invalidation-removing-and-replacing-stale-copies-soa-c03
- SAP-C03: Cache Invalidation: coordinating cached data with database writes (Premium), https://app.blowstack.com/lessons/cache-invalidation-coordinating-cached-data-with-database-writes-sap-c03
- SAA-C03: Cache Invalidation: database cache freshness (Premium), https://app.blowstack.com/lessons/cache-invalidation-database-cache-freshness-saa-c03
- AIP-C01: Cache Invalidation: validity rules for GenAI responses (Premium), https://app.blowstack.com/lessons/cache-invalidation-validity-rules-for-genai-responses-aip-c01
- SOA-C03: Time to Live versus Cache Invalidation (Premium), https://app.blowstack.com/lessons/time-to-live-versus-cache-invalidation-soa-c03
