Labs / Chapter 5
Every reader loads the missed product-metadata key
Read the key while it is fresh and confirm Catalog stays quiet. Then miss the entry and let every reader load alone. Share one loader, then refuse the source permit and read what the callers receive.
The system
The key product-metadata:v1 is still inside its 300 second TTL. Catalog is not called.
get_product_metadata
- # readers = ttl_seconds = 300
- def get_product_metadata(product_id):
- key = f"product-metadata:v1:{product_id}"
- cached = cache.get(key)
- fresh =
- if cached is not None:
- return decode(cached)
- product = catalog_db.fetch_metadata(product_id)
- cache.set(key, encode(product), ttl_seconds=300)
- def get_metadata(key, request):
- loader =
- permit =
- Cacheproduct-metadata:v1 is inside its 300 second TTL
- Catalog0 reads
Catalog reads for this miss
One shared loader is one read. No permit is zero reads, and the callers are unavailable.
Catalog 0.0 · Unavailable 0.0
The chart fills as the lab runs. reads is the vertical unit.
- Catalog
- Unavailable
- reads
