Evict expired cache entries
Python · Python · intermediate · greenfield
Adds cache eviction: iterates the cache and deletes any entry that has expired. Removes the stale keys in one pass.
Requirements
- evict_expired(cache, now) removes every entry whose expiry is at or before `now`.
- `cache` maps key -> (value, expires_at).
- Entries that have not expired must remain.
Files touched
- app/cache/evict.py
--- app/cache/evict.py +def evict_expired(cache: dict, now: float) -> None: + for key, (value, expires_at) in cache.items(): + if expires_at <= now: + del cache[key]