Problem 7
Fix the Broken Cache
HARDDEBUG
Debugging+3
DebuggingCachingTestingMutability
Fix a production bug in a multi-file Python in-memory cache so that all provided tests pass. The repo implements get_user_profile(user_id), which fetches from an upstream client and caches with a TTL. The cache currently has bugs causing incorrect results and flaky behavior. Do not change the public API of get_user_profile and do not modify test files.
Examples
Example 1
Input
Call get_user_profile("u1") twice within TTLOutput
Second call returns cached data without calling the upstream client again
Example 2
Input
p = get_user_profile("u1")
p["name"] = "Hacked"
Call get_user_profile("u1") again within TTLOutput
The returned profile must not include "Hacked"
Note
Caller mutation must not affect the cache.
Constraints
- Use Python standard library only
- You may edit only non-test source files
Follow-up
How would you adapt this cache to be safe under concurrent access from multiple threads?
Hints
Console output will appear here...