Caching Questions with Answers

30 practice questions on Caching (System Design) with answers and step-by-step solutions. Try 10 samples below, then practise all 30 free in the AptiNest app.

Sample questions

Question 1Easy

What does a CDN mainly do?

  1. Compile application code
  2. Host the primary database
  3. Replace the load balancer inside a data centre
  4. Cache content at edge servers close to users

Answer: D. Cache content at edge servers close to users

Explanation

A content delivery network serves static and cacheable content from edge locations, reducing latency and origin load.

Step-by-step solution

  1. A CDN is a network of edge servers spread around the world.
  2. It stores copies of static and cacheable content at those edges.
  3. Users are served from a nearby edge, which lowers latency and origin load.
  4. So a CDN caches content at edge servers close to users (option D).

Why the other options are wrong

  • A. A CDN does not compile application code.
  • B. A CDN serves cached copies; the primary database stays at the origin.
  • C. A CDN sits in front of the data centre; it does not replace the load balancer inside it.

Tip: CDNs help static and cacheable content; dynamic personal responses are usually not cached.

Question 2Easy

What is 'cache warming'?

  1. Raising all TTLs during peak load
  2. Flushing the whole cache on every deploy so that no stale data survives
  3. Increasing the cache server's temperature limit
  4. Pre-loading likely-needed data before traffic arrives

Answer: D. Pre-loading likely-needed data before traffic arrives

Explanation

Warming avoids a burst of misses after a restart or deploy by loading hot keys in advance.

Step-by-step solution

  1. Cache warming means loading likely-needed data ahead of time.
  2. This is done before traffic arrives, for example after a restart or deploy.
  3. It avoids a burst of misses when users arrive.
  4. So cache warming is pre-loading likely data before traffic (option D).

Why the other options are wrong

  • A. Raising TTLs is a separate setting and is not warming.
  • B. Flushing the whole cache is the opposite of warming; it empties the cache.
  • C. Cache warming has nothing to do with temperature limits.

Tip: Warm the cache with hot keys before traffic hits, so the first users avoid a miss storm.

Question 3Easy

In the cache-aside (lazy loading) pattern, on a cache miss the application:

  1. Writes a placeholder row to the database
  2. Returns an error to the client
  3. Waits for the cache to fetch the value from the database by itself
  4. Reads the database, then stores the result in the cache

Answer: D. Reads the database, then stores the result in the cache

Explanation

With cache-aside the application owns the logic: check cache, on miss load from the DB and populate the cache.

Step-by-step solution

  1. Cache-aside: the application checks the cache first.
  2. On a miss, the application reads the value from the database.
  3. The application then stores that value in the cache.
  4. So on a miss the application reads the database and fills the cache (option D).

Why the other options are wrong

  • A. No placeholder row is written; the application reads the existing data.
  • B. A miss is normal and does not return an error to the client.
  • C. In cache-aside the cache does not load data itself; the application does.

Tip: In cache-aside, the application owns the load and fill steps.

Question 4Easy

LRU eviction removes:

  1. The largest item
  2. The item accessed the fewest times
  3. The item inserted first, regardless of how often it is used
  4. The item not accessed for the longest time

Answer: D. The item not accessed for the longest time

Explanation

Least Recently Used evicts the entry whose last access is oldest.

Step-by-step solution

  1. LRU stands for Least Recently Used.
  2. Each access updates an entry's recency.
  3. When space is needed, the entry with the oldest last access is removed.
  4. So LRU removes the item not accessed for the longest time (option D).

Why the other options are wrong

  • A. Size is not the rule; LRU looks at access recency.
  • B. Fewest accesses is the rule for LFU, not LRU.
  • C. Insertion order alone is FIFO, not LRU.

Tip: LRU = least recently used; LFU = least frequently used; FIFO = first in, first out.

Question 5Medium

Which statement about caching and consistency is true?

  1. Caching removes the need for a database
  2. Caching trades some freshness for speed, so reads may be stale
  3. Caches make writes strongly consistent across every region
  4. A cache always returns the latest database value

Answer: B. Caching trades some freshness for speed, so reads may be stale

Explanation

Unless every write synchronously updates every cache, there is a window where cached data lags the source.

Step-by-step solution

  1. A cache holds a copy of data that may change in the source.
  2. Until the copy is updated or expires, reads can return older data.
  3. That is the trade: faster reads for some freshness.
  4. So reads may be stale, which makes option B the true statement (option B).

Why the other options are wrong

  • A. A cache sits in front of the database and does not replace it.
  • C. Caches do not make writes strongly consistent across regions by default.
  • D. A cache can return a value older than the database's latest.

Tip: A cache trades some freshness for speed; plan TTLs and invalidation around that.

Question 6Medium

Redis vs Memcached: which statement is accurate?

  1. Memcached supports sorted sets and streams; Redis supports only plain strings
  2. Both are relational databases
  3. Redis has rich data types and optional persistence; Memcached is simpler
  4. Redis cannot be used as a cache

Answer: C. Redis has rich data types and optional persistence; Memcached is simpler

Explanation

Redis offers lists, sets, sorted sets, streams and persistence; Memcached focuses on simple, multi-threaded key-value caching.

Step-by-step solution

  1. Redis offers rich data types such as lists, sets, sorted sets and streams.
  2. Redis can persist data to disk, optionally.
  3. Memcached is a simpler multi-threaded key-value cache.
  4. So Redis has rich types and optional persistence, while Memcached is simpler (option C).

Why the other options are wrong

  • A. This is reversed: Redis supports sorted sets and streams, and Memcached is plain key-value.
  • B. Neither is a relational database.
  • D. Redis is widely used as a cache, so it can be used as one.

Tip: Choose Redis for rich data types and persistence; Memcached for simple key-value caching.

Question 7Medium

Write-around caching is a good fit when:

  1. Every write must be readable immediately from the cache by all clients
  2. Written data is rarely read soon after
  3. Writes need the lowest possible latency
  4. The cache is the only store

Answer: B. Written data is rarely read soon after

Explanation

Write-around writes straight to the database and lets reads populate the cache, avoiding cache pollution from write-once data.

Step-by-step solution

  1. Write-around sends writes straight to the database and skips the cache.
  2. Reads populate the cache only when data is read.
  3. Data written once and rarely read soon after would only fill the cache with unused entries.
  4. So write-around fits when written data is rarely read soon after (option B).

Why the other options are wrong

  • A. Write-around skips the cache on writes, so new data is not readable from the cache at once.
  • C. Write-around is not the lowest-latency write path; it avoids cache work to keep the cache clean.
  • D. If the cache were the only store, nothing would be written to a database at all.

Tip: Write-around keeps write-once data out of the cache and avoids cache pollution.

Question 8Medium

A distributed cache spread across nodes adds what over a local in-process cache?

  1. No need for eviction
  2. Shared view across servers and more capacity, but a network hop
  3. Automatic strong consistency with the database on every single write and read
  4. Lower latency than local memory

Answer: B. Shared view across servers and more capacity, but a network hop

Explanation

A shared cache avoids each server holding its own copy but every access crosses the network.

Step-by-step solution

  1. A distributed cache is shared by all servers.
  2. It can hold more data than one server's memory.
  3. But every access crosses the network to reach it.
  4. So it gives a shared view and more capacity, at the cost of a network hop (option B).

Why the other options are wrong

  • A. A distributed cache still needs eviction when it is full.
  • C. A cache does not give automatic strong consistency with the database.
  • D. A network hop is slower than local memory, so it is not lower latency.

Tip: A local cache is fastest; a distributed cache is shared but adds network latency.

Question 9Hard

A cache uses LRU with capacity 3. Access sequence: A, B, C, A, D, B. Which keys are in the cache at the end?

  1. B, C, D
  2. A, D, B
  3. A, C, D
  4. A, B, C

Answer: B. A, D, B

Explanation

After A,B,C the cache is full. A is touched (order B,C,A). D evicts B (C,A,D). B evicts C (A,D,B).

Step-by-step solution

  1. Insert A, B, C; the cache is full. Order from oldest: A, B, C.
  2. Access A moves it to newest: B, C, A.
  3. Insert D: the oldest is B, so B is evicted, leaving C, A, D. Access B is a miss: the oldest is C, so C is evicted and B is added.
  4. Final contents: A, D, B (option B).

Why the other options are wrong

  • A. C was evicted when B was reloaded, so C is not in the cache.
  • C. B is in the cache at the end, and C was evicted before it.
  • D. B was evicted by D and then reloaded, while C was evicted, so A, B, C is not the result.

Tip: On a miss in a full LRU cache, evict the entry least recently used first.

Question 10Hard

With cache-aside, which write order is generally safer?

  1. Update the cache only and never the database
  2. Update the cache, then the database
  3. Delete the cache key, then update the database, with nothing else
  4. Update the database, then delete the cache key

Answer: D. Update the database, then delete the cache key

Explanation

Deleting after the DB commit avoids a reader repopulating the cache with the old value between the delete and the update; a small race remains, bounded by TTL.

Step-by-step solution

  1. Cache-aside writes go to the database and the cache is kept in step.
  2. If the cache is updated first, a failed database write leaves a wrong cached value.
  3. Updating the database first, then deleting the cache key, avoids a reader refilling the cache with an old value.
  4. So the safer order is update the database, then delete the cache key (option D).

Why the other options are wrong

  • A. Updating only the cache leaves the database stale, and the cache is lost if it fails.
  • B. Updating the cache first risks a stale value if the database write then fails.
  • C. Deleting first lets a reader refill the cache with the old value before the update lands.

Tip: In cache-aside, write the database first, then delete the cache key.

Practise all 30 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all System Design topics · All topics