# Caching

Caching stores reusable copies of data or computed results closer to consumers or on faster storage to reduce retrieval time and repeated work.

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

> A cache serves repeated requests without always accessing the original data source or recomputing a result. In cloud architectures, caching can reduce latency, origin load, and data transfer, but it requires deliberate decisions about freshness, capacity, security, and failure behavior.

Practice exams covering Caching: [ANS-C01 AWS Certified Advanced Networking - Specialty](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty), [AIF-C01 AWS Certified AI Practitioner](https://blowstack.com/practice-exams/aws-certified-ai-practitioner), [CLF-C02 AWS Certified Cloud Practitioner](https://blowstack.com/practice-exams/aws-certified-cloud-practitioner), [SOA-C03 AWS Certified CloudOps Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate), [DVA-C02 AWS Certified Developer - Associate](https://blowstack.com/practice-exams/aws-certified-developer-associate), [DOP-C02 AWS Certified DevOps Engineer - Professional](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional), [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional), [MLA-C02 (beta) AWS Certified Machine Learning Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate), [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 Caching

Effective caching balances access speed and source-load reduction against freshness, capacity, security, and the consequences of misses or buffered writes.

1. **Faster access through proximity**: Place reusable data near consumers or on lower-latency storage. Edge caches shorten network paths for users, while local storage caches reduce repeated access across a wide-area connection.
2. **Cache hits and misses**: Hits avoid some or all source retrieval work; misses still require the source or an upstream cache. Measure hit ratio alongside latency and source traffic to determine whether caching helps the workload.
3. **Freshness and invalidation**: Expiration, explicit invalidation, and versioned identifiers control how cached data changes over time. Choose a strategy that matches how much stale data the application can tolerate.
4. **Finite capacity and eviction**: A cache usually holds a working set rather than the complete dataset. Size it for access patterns and monitor evictions, because frequently removing useful entries increases misses.
5. **Write handling and durability**: Some caches accelerate reads only, while others buffer writes before updating backing storage. With asynchronous writes, local acknowledgment does not necessarily mean the backing cloud store has received the data.
6. **Isolation and failure behavior**: Cache keys and access controls must prevent unintended sharing of private data. Plan for cold caches and outages so that sudden misses do not overwhelm the authoritative source.

## Cloud services for Caching

These services apply caching at different points rather than forming a required stack. Amazon CloudFront caches eligible web content near users, AWS Storage Gateway keeps a local working set for hybrid storage access, and Amazon ElastiCache supports application-level reuse of data and results. A system can use several of these layers, but each needs its own freshness and failure strategy. Updating a database or cloud object does not automatically invalidate every cached representation, so engineers must coordinate expiration, invalidation, or versioning where the layers overlap.

- **[Amazon CloudFront](https://blowstack.com/tools/cloud-services-hub/amazon-cloudfront)**: Caches eligible HTTP content at distributed edge locations to serve users with lower latency and reduce origin requests. Cache keys, expiration settings, and invalidations determine what is reused and for how long.
- **[AWS Storage Gateway](https://blowstack.com/tools/cloud-services-hub/aws-storage-gateway)**: Provides hybrid storage capabilities, including Amazon S3 File Gateway, which caches cloud-backed file data locally for NFS or SMB access. Its Volume Gateway also offers cached volumes, which are block storage rather than file shares.
- **[Amazon ElastiCache](https://blowstack.com/tools/cloud-services-hub/amazon-elasticache)**: Provides managed in-memory caching using engines such as Valkey, Redis OSS, and Memcached. Applications can use it to reuse frequently requested data or computed results instead of repeatedly querying databases or performing expensive calculations.

## Caching exam questions

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

### Question 1 (AIF-C01)

**Question:**

A software company uses an Amazon Bedrock foundation model to review code changes. Each prompt contains a unique request ID, followed by a long, unchanged set of coding standards, followed by the code to review. The company enables prompt caching on a supported model but observes almost no cache hits. The coding standards meet the model's minimum cacheable length, and requests arrive within the cache's supported lifetime. Each code change requires a new review. Which change should the company make to reduce repeated input processing?

**Correct answer:** Place the unchanged coding standards first, mark that shared prefix for caching, and place the request ID and code after it.

**Explanation:** Prompt caching can reuse processing for an identical prompt prefix. Placing the stable coding standards before the changing content enables reuse while allowing the model to generate a fresh review for each code change.

### Question 2 (MLA-C02 (beta))

**Question:**

A news application uses an Amazon Bedrock foundation model to summarize articles. Multiple application replicas share a response cache keyed by the complete inference request. Cached summaries remain valid for 1 hour. When a popular new article appears, hundreds of identical requests arrive across the replicas before the first summary is generated. Logs show that each request invokes Bedrock on a cache miss, causing a spike in inference charges even though subsequent requests achieve a high cache hit rate. Generating a summary takes approximately 2 seconds, and callers can wait for the first summary to become available. The company must reduce these duplicate invocations without delaying requests for unrelated articles. Which change should an ML engineer implement?

**Correct answer:** Use an atomic distributed lease for each cache key. The lease holder checks the cache again, invokes Bedrock if needed, and stores the result. Other callers wait for that result, with bounded retries and recovery if the lease holder fails.

**Explanation:** Per-key request coalescing prevents a cache stampede across replicas. One caller generates the missing summary while other callers reuse its result. Separate leases allow unrelated articles to proceed independently, and lease expiration provides failure recovery.

### Question 3 (SAP-C03)

**Question:**

A company uses one Amazon CloudFront distribution with separate cache behaviors for two custom HTTPS origins:

• /images/* serves product images generated on demand. Image URLs identify immutable transformation results. The origin charges the company for each transformation and does not retain generated results. CloudFront serves 99% of viewer requests from its existing caches. However, the remaining 2 million monthly origin requests frequently request identical image URLs through different regional edge caches.
• /exports/* serves customer-specific archive files. Each archive has a unique URL, is downloaded exactly once, and is then deleted. These requests account for most of the company's origin data transfer volume. Archives are eligible for caching, but no two requests use the same URL.

A solutions architect is evaluating an optional additional CloudFront caching layer. For this evaluation, assume that the layer costs $0.01 per 10,000 requests reaching it, with no other incremental charges. Trace-based modeling predicts that it would eliminate 80% of the current image-origin requests. Each image-origin request costs $0.005 for transformation, excluding data transfer. The export workload generates 20 million requests monthly. Neither workload's URLs, retention rules, or request patterns can change.

Which configuration will minimize total recurring cost?

**Correct answer:** Enable CloudFront Origin Shield only for the image origin, using the available Origin Shield Region with the lowest latency to that origin. Leave the export origin unchanged.

**Explanation:** Origin Shield consolidates cache misses from different regional edge caches, making it suitable for reusable content that is expensive to generate. Eliminating 80% of 2 million image-origin requests avoids 1.6 million transformations, saving $8,000 monthly before any transfer savings. The additional request charge is only $2 monthly. Unique, single-download exports cannot benefit from cache consolidation, so leaving that origin unchanged avoids $20 in additional monthly charges.

### Question 4 (CLF-C02)

**Question:**

A branch office uses AWS Storage Gateway with an S3 File Gateway to access a large collection of documents. During a test with normal network connectivity, an employee opens a document that has never been accessed through the gateway. The first read is slower than subsequent reads of the same document. Which statement best explains this behavior?

**Correct answer:** The gateway initially retrieves the document from Amazon S3 and then can serve subsequent reads from its local cache.

**Explanation:** S3 File Gateway caches accessed file data locally. An initial read of uncached data requires retrieval from Amazon S3, while subsequent reads can use the local cache to reduce latency.

### Question 5 (SOA-C03)

**Question:**

A company runs an API on an Amazon EC2 Auto Scaling group. The API caches expensive calculations for immutable historical datasets in a node-based Amazon ElastiCache for Valkey replication group. Cache entries have no expiration because the underlying datasets never change. On a cache miss, the application recalculates the result and stores it in the cache.

As users request more datasets, cache memory fills with results that are rarely requested again. The primary node begins rejecting cache writes. The frequently reused results fit comfortably in the primary node's memory, and cache CPU utilization is low. The current maxmemory-policy is noeviction.

A CloudOps engineer must allow new results to be cached by automatically removing less recently used results when memory is full. The solution must retain the current primary node type and require no application changes.

Which change meets these requirements?

**Correct answer:** Change the maxmemory-policy to allkeys-lru.

**Explanation:** The allkeys-lru policy can evict keys regardless of whether they have an expiration, preferentially removing less recently used entries through an approximate LRU algorithm. This allows new results to be cached while retaining frequently reused results, without resizing the primary or changing application code.

### Question 6 (AIP-C01)

**Question:**

A company uses Amazon Bedrock to generate answers for two request categories. A trusted application component identifies the category before generation. The company pilots a semantic response cache that checks authorization, input context, and source versions before accepting a match. Evaluation confirms that every accepted match can safely reuse the stored answer.

The pilot produces the following measurements:

| Request category | Average generation cost without caching | Eligible cache-hit rate |
|---|---:|---:|
| Product guidance | $0.002 per request | 60% |
| Specialized engineering analysis | $0.020 per request | 2% |

For either category, enabling the cache adds $0.0005 to EVERY request, including misses. This amount includes embedding generation, lookup, and amortized cache storage and write costs. A cache hit avoids the entire generation cost. A cache miss invokes the original model once, at the same average generation cost shown in the table. Both categories have substantial traffic, and the measurements are representative of future requests. All configurations meet the application's quality and latency requirements.

Which cache deployment policy will minimize expected recurring cost?

**Correct answer:** Enable the semantic response cache only for product guidance.

**Explanation:** Product guidance costs $0.0005 + (1 − 0.60) × $0.002 = $0.0013 per request with caching, saving $0.0007 compared with generation alone. Engineering analysis would cost $0.0005 + (1 − 0.02) × $0.020 = $0.0201, exceeding its $0.020 baseline. Enabling caching only for product guidance therefore minimizes expected recurring cost.

### Question 7 (DVA-C02)

**Question:**

A developer maintains an Amazon API Gateway REST API with a read-only POST /availability/{sku} method. Requests have no body. The backend returns inventory availability based on the sku path parameter and the X-Warehouse request header. Responses can be shared among all callers requesting the same SKU and warehouse. A cache cluster is provisioned for the deployed stage, but only the default method-level caching settings are in use. The sku path parameter is already configured as a cache key parameter. During repeated identical POST requests, the backend is invoked every time. Which configuration will allow these requests to reuse cached responses without returning availability for the wrong warehouse?

**Correct answer:** Enable caching in the POST method's stage override, declare X-Warehouse as a method request header, and select that header as an additional cache key parameter.

**Explanation:** API Gateway enables caching only for GET methods by default when stage caching is enabled. The POST method requires a method-level caching override. Including X-Warehouse in the cache key, alongside the configured sku parameter, creates separate cached responses for each SKU and warehouse combination.

### Question 8 (DOP-C02)

**Question:**

A company runs a reporting API on 80 application instances. All instances use a shared Amazon ElastiCache for Redis OSS replication group to cache an expensive database aggregation under one key. The cached result currently expires after 60 seconds. During peak traffic, expiration causes hundreds of requests to recompute the same aggregation concurrently, saturating the database.

A single aggregation completes within 5 seconds when the database is not overloaded. The business permits serving a previously generated result for up to 90 seconds after its generation timestamp. Requests that arrive while a refresh is running should receive an acceptable cached result immediately, if one is available. Adding database capacity is not permitted.

A DevOps engineer must prevent concurrent recomputation of this key across the application fleet during normal operation and allow another instance to refresh the result if the refreshing instance fails. Assume ElastiCache remains available.

Which implementation meets these requirements?

**Correct answer:** Retain the result with its generation timestamp for up to 90 seconds and initiate refresh after 60 seconds. Acquire a shared per-key lock with SET NX and a 15-second expiration before recomputing. Use an ownership token and atomic owner-checked release. Other requests serve the result only while its age is within 90 seconds; otherwise, they wait and recheck rather than recompute without the lock.

**Explanation:** Separate refresh and expiration thresholds allow acceptable stale results to be served without waiting for recomputation. The shared lock coalesces refreshes across the fleet, and its expiration allows recovery if the owner fails. The lock lifetime exceeds the stated normal computation time. Ownership-checked release prevents a former owner from deleting a replacement owner's lock, and timestamp checks enforce the maximum acceptable result age.

### Question 9 (SAA-C03)

**Question:**

An engineering company distributes public reference archives from an HTTPS server in its on-premises data center. Customers worldwide repeatedly download the same archives, especially after weekly announcements. Published archives never change. The company's internet provider charges for outbound data, and download spikes frequently saturate the data center's internet connection.

The company must keep the authoritative files on premises. It wants to reduce data center outbound traffic and improve download performance without operating additional download servers.

Which solution meets these requirements with the LEAST operational overhead?

**Correct answer:** Create an Amazon CloudFront distribution with the on-premises HTTPS server as a custom origin. Configure caching with a long TTL for the archive paths and direct customers to the distribution.

**Explanation:** CloudFront supports publicly accessible HTTPS servers outside AWS as custom origins. Edge caches can reuse the immutable archives for subsequent downloads, reducing data center outbound traffic and improving global performance without moving the authoritative files or managing more servers.

### Question 10 (ANS-C01)

**Question:**

A company distributes versioned software documentation to customers worldwide through an Amazon CloudFront distribution with an on-premises HTTPS origin. The origin's internet connection is approaching capacity. Each request contains a lang query parameter that selects the document language and a globally unique requestId query parameter used for troubleshooting. Document content depends only on the URL path and lang; published versions never change. The origin returns Cache-Control: public, max-age=86400. The current cache policy includes all query parameters, and monitoring shows a very low cache hit ratio despite frequent downloads of the same documents in the same languages. The company must preserve language-specific responses and retain requestId at the origin whenever an origin fetch occurs. Client and origin application changes are not permitted. Which configuration change will most effectively reduce origin bandwidth utilization while meeting these requirements?

**Correct answer:** Configure the cache policy to include only lang among the query parameters. Configure an origin request policy to forward requestId without including it in the cache key.

**Explanation:** This allows requests for the same document and language to share a cached response, regardless of their unique requestId values. Query parameters included in the cache key are automatically forwarded to the origin. The origin request policy additionally forwards requestId on origin fetches without fragmenting the cache, reducing repeated transfers over the origin's internet connection.

## Practice Caching in a full exam

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

- [SAA-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate): 25 questions
- [SOA-C03](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate): 23 questions
- [SAP-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional): 10 questions
- [CLF-C02](https://blowstack.com/practice-exams/aws-certified-cloud-practitioner): 10 questions
- [DVA-C02](https://blowstack.com/practice-exams/aws-certified-developer-associate): 8 questions
- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 6 questions
- [MLA-C02 (beta)](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate): 4 questions
- [ANS-C01](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty): 4 questions
- [AIF-C01](https://blowstack.com/practice-exams/aws-certified-ai-practitioner): 3 questions
- [DOP-C02](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional): 3 questions

## What is Caching

Caching places reusable data or results where they can be retrieved more efficiently than from their original source. The original source, often called the origin or system of record, normally remains authoritative. A cache might hold website images, database query results, application objects, or recently accessed file data. Its value comes from reuse: repeatedly reading the same information becomes faster or less expensive.

A cache hit occurs when the requested data is available and usable in the cache. A cache miss requires fetching the data from its source or computing it, often followed by storing it for subsequent requests. Hit ratio measures the proportion of requests served from the cache. A high hit ratio generally reduces source traffic, but performance also depends on object sizes, retrieval latency, and the overhead of looking up cached entries.

Cloud content delivery networks apply caching at edge locations distributed near users. For example, a user requesting a product image can receive a cached copy from a nearby edge location instead of retrieving it repeatedly from a distant application or storage origin. This reduces network travel time and origin requests. AWS edge locations support services such as Amazon CloudFront; they are not interchangeable with AWS Regions or Availability Zones, and they do not automatically cache every AWS workload.

Not every edge request is a cache hit. The requested object may be absent, expired, evicted, or configured not to be cached. The delivery service then retrieves it through its upstream path. Dynamic or personalized responses require particular care: caching a response under a key that does not distinguish users or relevant request attributes can expose one user's data to another. Cache policies must reflect the application's authorization and content variation requirements.

Hybrid storage uses the same principle in a different location. An on-premises gateway can retain frequently accessed cloud-backed file data on local disks. Applications continue using familiar file protocols while local cache hits avoid repeatedly downloading data across the wide-area network. Amazon S3 File Gateway, part of AWS Storage Gateway, provides NFS or SMB access to files stored as Amazon S3 objects and maintains a local cache. Writes are buffered locally and uploaded asynchronously, so monitoring upload progress and protecting local disks matter.

A local file cache does not imply that the complete dataset is available locally. Accessing uncached data requires connectivity to its backing storage, and disconnected operation is limited by cached content and gateway behavior. Also distinguish Storage Gateway cached volumes from stored volumes: cached volumes keep primary data in Amazon S3 with frequently accessed data cached locally, whereas stored volumes keep the complete primary volume locally and asynchronously back it up to AWS. These volume modes expose block storage, not file shares.

Freshness is a central trade-off. A time to live limits how long an entry is considered fresh, while invalidation explicitly removes or expires entries after a change. Neither approach should be assumed to provide immediate consistency across every cache. Versioned object names are useful for static assets because a new filename identifies new content without depending on immediate removal of the old copy.

Caches have finite capacity, so eviction policies remove entries to make room. Cold starts, mass expiration, or cache failure can suddenly increase load on the source; applications should tolerate misses and protect dependencies from request surges. Measure hit ratio, latency, evictions, source load, and total cost rather than assuming that a larger cache is always better. Finally, caching is not a backup strategy: cached copies may be incomplete, stale, or disposable, and pending writes require separate durability considerations.

## Learn Caching in lessons

15 short lessons on Caching in 8 certification courses.

- AIF-C01: Caching: prompt reuse in foundation models (Premium), https://app.blowstack.com/lessons/caching-prompt-reuse-in-foundation-models-aif-c01
- MLA-C02 (beta): Caching: reusing foundation model inference work (Premium), https://app.blowstack.com/lessons/caching-reusing-foundation-model-inference-work-mla-c02
- SAP-C03: Caching: content-delivery cache policies (Premium), https://app.blowstack.com/lessons/caching-content-delivery-cache-policies-sap-c03
- CLF-C02: Caching: keeping reusable data close to readers (Premium), https://app.blowstack.com/lessons/caching-keeping-reusable-data-close-to-readers-clf-c02
- SOA-C03: Caching: implementing read offloading with AWS services (Premium), https://app.blowstack.com/lessons/caching-implementing-read-offloading-with-aws-services-soa-c03
- AIP-C01: Precomputation vs. caching (Premium), https://app.blowstack.com/lessons/precomputation-vs-caching-aip-c01
