5 exercises on cache eviction strategies vocabulary.
0 / 5 completed
1 / 5
What does a Least Recently Used (LRU) cache eviction policy do?
LRU: maintains access order and discards the least recently accessed item on overflow. It is based on temporal locality: recently used items are likely to be used again soon. Implemented efficiently with a hash map and doubly-linked list.
2 / 5
When is a Least Frequently Used (LFU) policy preferable to LRU?
LFU: tracks access count and evicts the least frequently accessed item. It suits workloads with a stable "hot set" — popular items stay in cache even if briefly unused. However, it is harder to implement and slow to adapt to access pattern shifts.
3 / 5
What is a Time-To-Live (TTL) based eviction?
TTL eviction: items are automatically invalidated after a set time, ensuring data staleness is bounded. It is ideal for data that changes predictably (e.g., exchange rates, configuration) where stale-reads beyond a threshold are unacceptable.
4 / 5
What is a cache hit ratio and why does it matter?
Hit ratio: (hits / (hits + misses)) × 100. A low ratio means most requests bypass the cache and hit the origin, undermining caching's purpose. Choosing the right cache size, TTL, and eviction policy directly affects hit ratio.
5 / 5
What is a write-through cache strategy?
Write-through: every write updates both the cache and the backing store synchronously. The cache is always consistent with the database. Writes are slower than write-back, but reads after writes always hit the cache with fresh data.