Cloud concept · Updated

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

In short

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.

Cloud Concepts Hub →

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.

01
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.

02
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.

03
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.

04
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.

05
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.

06
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 CloudFrontAmazon 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 GatewayAWS 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 ElastiCacheAmazon 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. Answer them with every option in the exam simulator.

AIF-C01

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?

Show answerCORRECT ANSWER

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

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.

MLA-C02 (beta)

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?

Show answerCORRECT 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.

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.

SAP-C03

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?

Show answerCORRECT 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.

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.

Practice Caching in a full exam

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

Start a free practice exam

What is Caching

3 min read

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.

and 9 more lessons

Open the lessons