Script Valley
Redis: Complete Course
Caching Patterns/Assessment

Practice & Assessment

Test your understanding of Caching Patterns

Multiple Choice Questions

5
1

In cache-aside, what happens on a cache miss?

2

Which eviction policy should you use when all your cached data also lives in a database?

3

What is a cache stampede?

4

In write-through caching, when is the database updated?

5

Which command creates a Redis lock atomically, preventing a race condition?

Coding Challenges

1
1

Cache-Aside API Endpoint

Implement a getArticle(id) function using cache-aside. On a cache miss, simulate a 200 ms database call (setTimeout). Cache the result in Redis for 2 minutes under the key article:<id>. Log 'CACHE HIT' or 'CACHE MISS' on each call. Call getArticle with the same id 5 times in sequence and verify only the first call triggers a miss. Input: integer article id. Output: article object and cache status log. Estimated time: 20 minutes.

Easy

Mini Project

1

Multi-Layer Caching API

Build a REST API (Express.js or FastAPI) with three endpoints: GET /products/:id (cache-aside, TTL 5 min), PUT /products/:id (write-through โ€” update DB mock and Redis simultaneously, then return updated product), DELETE /products/:id (invalidate cache key on delete). Add a GET /products/:id/stats endpoint that returns cache_hits and cache_misses counters stored as Redis Strings with INCR. Use tag-based invalidation: each product key is also tracked in a tag Set product-category:<categoryId>. Add a POST /admin/invalidate-category/:id endpoint that deletes all product cache keys in that category. Demonstrate all five endpoints working together.

Medium
Practice & Assessment โ€” Caching Patterns โ€” Redis: Complete Course โ€” Script Valley โ€” Script Valley