0 votes
in AWS by

Your development team is planning on using AWS ElastiCache - Redis for their caching implementation. It needs to be ensured that data is only filled in the cache when it is required.

Which of the following cache strategy can be used for this purpose?

1 Answer

0 votes
by

Answer - A.

Option B is incorrect since this is used to add data or updates data in the cache whenever data is written to the database.

Option C is incorrect since this is used to specify the number of seconds (Redis can specify seconds or milliseconds) until the key expires.

Option D is incorrect since this is used in useful in recovery scenarios.

This is mentioned in the AWS Documentation.

Advantages of Lazy Loading.

Only requested data is cached.

Since most data is never requested, lazy loading avoids filling up the cache with data that isn't requested.

Node failures are not fatal.

When a node fails and is replaced by a new, empty node, the application continues to function, though with increased latency.

As requests are made to the new node, each cache miss results in a query of the database and adding the data copy to the cache so that subsequent requests are retrieved from the cache.

For more information on the caching strategies, please visit the following URL-

https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Strategies.html

The caching strategy that can be used to ensure that data is only filled in the cache when it is required is "Lazy loading." Lazy loading is a technique where data is only loaded into the cache when it is requested by the application, and not preloaded into the cache. This technique helps to reduce the memory usage of the cache, as it only stores data that is actually used by the application.

The other cache strategies listed in the question are as follows:

B. Write through: In this strategy, data is written to the cache and the underlying database at the same time. This ensures that data is always up-to-date in the cache, but can be less performant than lazy loading.

C. Adding a TTL: A time-to-live (TTL) value can be set for cached data, which determines how long the data will remain in the cache before it is automatically removed. This strategy can be useful for controlling the size of the cache, but does not necessarily ensure that data is only loaded into the cache when it is required.

D. Use Redis AOF: Redis AOF (append-only file) is a persistence mechanism that logs every write operation to a file. This allows Redis to recover data in the event of a crash, but does not specifically relate to cache loading strategies.

In summary, lazy loading is the caching strategy that can be used to ensure that data is only filled in the cache when it is required.

...