Top 18 Caching interview questions and answers in 2021.
You can check all 18 Caching interview questions here π https://devinterview.io/design/caching-interview-questions
πΉ 1. What is Caching?
Answer:
In computing, a cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the dataβs primary storage location. Caching allows you to efficiently reuse previously retrieved or computed data.
πΉ 2. Is Redis just a cache?
Answer:
Like a cache Redis offers:
- in memory key-value storage
But unlike a cash Redis:
- Supports multiple datatypes (strings, hashes, lists, sets, sorted sets, bitmaps, and hyperloglogs)
- It provides an ability to store cache data into physical storage (if needed).
- Supports pub-sub model
- Redis cache provides replication for high availability (master/slave)
- Supports ultra-fast lua-scripts. Its execution time equals to C commands execution.
- Can be shared across multiple instances of the application (instead of in-memory cache for each app instance)
πΉ 3. What is Resultset Caching?
Answer:
Resultset caching is storing the results of a database query along with the query in the application. Every time a web page generates a query, the applications checks whether the results are already cached, and if they are, pulls them from an in-memory data set instead. The application still has to render the page.
πΉ 4. What is Cache Invalidation?
Answer:
There are only two hard things in Computer Science: cache invalidation and naming things.
β Phil Karlton
HTTP caching is a solution for improving the performance of your web application. For lower load on the application and fastest response time, you want to cache content for a long period (TTL). But at the same time, you want your clients to see fresh (validate the freshness) content as soon as there is an update.
Cache invalidation gives you the best of both worlds: you can have very long TTLs, so when content changes little, it can be served from the cache because no requests to your application are required. At the same time, when data does change, that change is reflected without delay in the web representations.
πΉ 5. What usually should be cached?
Answer:
The results for the following processes are good candidates for caching:
- Long-running queries on databases,
- high-latency network requests (for external APIs),
- computation-intensive processing
πΉ 6. Name some Cache Writing Strategies
Answer:
There are two common strategies to write data in a cache:
- Pre-caching data, for small pieces of data, usually during the application initialization, before any request.
- On-demand, checking first if the requested data is in the cache (if the data is found, it is called a cache hit), using it, improving the performance of the application. Whenever the requested data has not been written to the cache (cache miss), the application will need to retrieve it from the slower source, then writing the results in the cache, thus saving time on subsequent requests for the same data.
πΉ 13. What is the difference between Cache replacement vs Cache invalidation?
Thanks π for reading and good luck on your next tech interview!
Explore 3800+ dev interview question here π Devinterview.io