There are two caching strategies available: Lazy Loading and Write-Through
Lazy Loading
Loads the data into the cache only when necessary (if a cache miss occurs).
Lazy loading avoids filling up the cache with data that won’t be requested.
If requested data is in the cache, ElastiCache returns the data to the application.
If the data is not in the cache or has expired, ElastiCache returns a null.
The application then fetches the data from the database and writes the data received into the cache so that it is available for next time.
Data in the cache can become stale if Lazy Loading is implemented without other strategies (such as TTL).
Write Through
When using a write-through strategy, the cache is updated whenever a new write or update is made to the underlying database.
Allows cache data to remain up to date.
This can add wait time to write operations in your application.
Without a TTL you can end up with a lot of cached data that is never read.
Dealing with stale data – Time to Live (TTL)
The drawbacks of lazy loading and write through techniques can be mitigated by a TTL.
The TTL specifies the number of seconds until the key (data) expires to avoid keeping stale data in the cache.
When reading an expired key, the application checks the value in the underlying database.
Lazy Loading treats an expired key as a cache miss and causes the application to retrieve the data from the database and subsequently write the data into the cache with a new TTL.
Depending on the frequency with which data changes this strategy may not eliminate stale data – but helps to avoid it.
Exam tip: Compared to DynamoDB Accelerator (DAX) remember that DAX is optimized for DymamoDB specifically and only supports the write-through caching strategy (does not use lazy loading).
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (