Caching — Redis, TTLs & Invalidation — Concept Check
Questions on Caching — Redis, TTLs & Invalidation. Cache-aside with redis.asyncio: read the cache, miss → compute and SETEX with a TTL, write → invalidate. Design keys with versioned prefixes, guard hot keys against stampedes, and set HTTP Cache-Control for the layers you don't own.
Questions in this quiz
7 questions on Caching — Redis, TTLs & Invalidation — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A service using Redis cache-aside pattern experiences a sudden spike in database load. What might be the cause?
- ARedis server crashed, losing all cached data.
- BA hot key expired, causing a cache stampede.
- CThe cache TTL was set too long, causing stale data.
- DThe database schema was changed without updating cache keys.
2.When using cache-aside with Redis, what should you do after writing new data to the database?
- AReduce the TTL of existing cache keys.
- BCreate new cache keys for the data.
- CInvalidate the affected cache keys.
- DIncrease the TTL of existing cache keys.
3.A developer notices that different users are receiving the same cached data. What is likely the problem?
- AThe cache keys do not include user-specific identifiers.
- BThe Redis server is not configured for multi-tenancy.
- CThe TTLs are too short, causing frequent cache misses.
- DThe cache is using an in-process dict instead of Redis.
4.Why is it important to set a TTL for every cache key, even with explicit invalidation?
- ATTL acts as a safety net for forgotten invalidations.
- BTTL helps in versioning cache keys effectively.
- CTTL ensures data is always fresh and up-to-date.
- DTTL prevents the cache from consuming too much memory.
5.What is a potential risk of not using versioned prefixes in cache keys?
- AStale cache entries may persist after data structure changes.
- BData might be cached across different environments.
- CRedis may not support unversioned keys.
- DCache keys may become too long and inefficient.
6.A developer sets a Cache-Control header as 'public, max-age=300'. What does this imply?
- AThe response is only cached by the user's browser.
- BThe response can be cached by any cache, including CDNs.
- CThe response should not be cached at all.
- DThe response is private and should not be cached by CDNs.
7.What happens if a CDN caches a per-user response under a shared URL?
- AIt results in faster load times for all users.
- BIt improves performance by reducing server load.
- CIt leads to a data breach, exposing private data.
- DIt causes cache keys to expire prematurely.