Caching Junior
What is a cache, and what are the primary reasons for adding one to a system?
Select the correct answer
A load balancer that distributes incoming requests across many backend app servers
A fast store of data copies that lowers latency and reduces load on the source
A queue that buffers write requests so the backing store is updated asynchronously
A backup database replica kept in sync to provide durability if the primary fails
What is the difference between a cache hit and a cache miss, and what do we mean by a 'cold' versus a 'warm' cache?
Select the correct answer
Hit finds data in cache, miss does not; cold is unpopulated, warm is populated
Hit means data is fresh, miss means data is stale; cold is old, warm is recently written
Hit is a successful eviction, miss is a failed one; cold has low memory, warm has high
Hit writes to cache, miss reads from cache; cold is slow startup, warm is steady state
What is the difference between memoization and caching?
Select the correct answer
Memoization is used for databases while caching applies only to pure side functions.
Caching requires manual invalidation but memoization automatically refreshes entries.
Memoization stores function results by arguments; caching is the broader concept.
Caching only works in memory while memoization always persists its results to disk.
What happens to a cache when it reaches its memory limit but no TTLs have expired yet?
Select the correct answer
It flushes the entire cache and starts cold to guarantee free memory now exists.
It rejects all new writes until some existing key's TTL eventually expires soon.
It evicts existing entries based on its configured eviction policy to free space.
It spills the overflow entries onto disk automatically without evicting anything.
What happens to a cached resource when a 'Conditional GET' (If-None-Match) returns a 304 Not Modified?
Select the correct answer
The cached copy is served and its freshness lifetime is renewed without downloading the body
The cached copy is discarded and the full resource is re-downloaded from the origin server
The cached copy is served but immediately marked stale, forcing another request next time
The cached copy's body is partially updated using the delta returned within the response
How does a sliding TTL differ from a fixed TTL?
Select the correct answer
Sliding TTL expires at a fixed wall-clock time, while fixed TTL extends on every read access
Sliding TTL applies only to writes, while fixed TTL applies only to read operations of keys
Sliding TTL resets the expiry on each access, while fixed TTL expires at a set time after write
Sliding TTL guarantees stronger consistency, while fixed TTL allows serving arbitrarily stale data
What is the difference between an In-Process (Local) cache and a Distributed (Remote) cache? When would you choose one over the other?
Select the correct answer
In-process persists data to disk for durability; distributed only holds data in volatile memory and loses everything whenever a single node restarts.
In-process lives in the app's own memory and is fastest but unshared; distributed runs as a shared service with network cost but consistency.
In-process scales horizontally by adding nodes automatically; distributed is limited to one machine's RAM and cannot grow beyond that fixed capacity.
In-process is shared across all servers over the network; distributed is private per instance and avoids any serialization or coherence problems entirely.