What is caching?
Caching stores frequently accessed data in a fast-access layer (memory) to reduce latency and load on the primary data source. It trades memory for speed.
What are the different types of cache?
Main types: Client-side cache (browser), CDN cache (edge servers), Application cache (Redis/Memcached), Database cache (query results), CPU cache (hardware level).
What is cache invalidation?
Cache invalidation is removing or updating stale data from cache. It’s one of the hardest problems in CS. Strategies include TTL (time-to-live), write-through, and event-based invalidation.
What is the difference between cache-aside and write-through?
Cache-aside: Application reads from cache, loads from DB on miss, and updates cache. Write-through: Application writes to cache, which synchronously writes to DB. Write-through ensures consistency.
What is a CDN (Content Delivery Network)?
A CDN is a geographically distributed network of proxy servers that cache content closer to users. It reduces latency, bandwidth costs, and load on origin servers.
What is cache eviction?
Cache eviction removes items when cache is full. Common policies: LRU (Least Recently Used), LFU (Least Frequently Used), FIFO (First In First Out), Random.
What is Redis?
Redis is an in-memory data store used as a cache, message broker, and database. It supports various data structures (strings, lists, sets, hashes) and offers persistence options.
What is Memcached?
Memcached is a distributed memory caching system for speeding up dynamic web applications by reducing database load. It’s simpler than Redis with key-value storage only.
When should you not use caching?
Avoid caching for: frequently changing data, data requiring strong consistency, large datasets that don’t fit in memory, or when cache overhead exceeds benefits.
What is cache stampede?
Cache stampede (thundering herd) occurs when many requests simultaneously try to regenerate a cache entry after expiration. Solutions include lock-based regeneration or probabilistic early expiration.