DVA-C02 Question 104
Single answerYou are developing a high-traffic e-commerce application that uses an Amazon DynamoDB table to store product details. To improve performance and reduce read latency, you decide to integrate Amazon ElastiCache as a caching layer. Which caching strategy is most appropriate if you want to ensure that the cache always contains the most up-to-date product details whenever data is updated in DynamoDB?
- A
Write-through caching
- B
Read-through caching
- C
Lazy loading
- D
Cache-aside with time-to-live (TTL)
Show answer and explanation
Correct answer: A
Explanation
Write-through caching is the best choice when you need to ensure that the cache always contains the most up-to-date data. In this strategy, updates to the database are immediately mirrored in the cache, eliminating the risk of stale data. Other strategies, such as lazy loading or cache-aside, may result in stale data in the cache since they update the cache only after a cache miss or when TTL expires.
- A. Correct.
Write-through caching ensures that whenever data is written to the database, it is also written to the cache simultaneously. This guarantees that the cache is always up-to-date, making it the most appropriate strategy in this scenario.
- B. Incorrect.
Read-through caching is used to fetch data from the cache or the database when a read request is made. However, it does not ensure that the cache is updated when the database is updated, so this is not suitable for the given requirement.
- C. Incorrect.
Lazy loading populates the cache only when a cache miss occurs. While it reduces initial cache overhead, it does not ensure that the cache is updated when DynamoDB data changes, which makes it unsuitable for this scenario.
- D. Incorrect.
Cache-aside with time-to-live (TTL) allows data to expire after a set duration, requiring a database fetch on expiration. While it can reduce stale data, it does not guarantee immediate synchronization with DynamoDB upon updates.