Welcome to the team that owns the caching tier. A capacity-bounded LRU cache serves hot values; both get and put count as using a key, and when capacity is exceeded the least-recently-used entry is evicted.
Welcome to the team that owns the caching tier. A capacity-bounded LRU cache serves hot values; both get and put count as using a key, and when capacity is exceeded the least-recently-used entry is evicted.
This repository has three reported problems, listed below as tickets. Fix as many tickets as you can in 45 minutes. Each ticket is checked separately, and you are not expected to finish every one.
You may use the AI assistant and normal repository tools. Treat the assistant like a junior developer: establish a plan, inspect its work, run the tests, and retain ownership of the result.
cache/
lru.py LRUCache: get / put with LRU eviction
errors.py CacheError
service.py CacheService: get / put
tests/visible/ shipped regression tests
conftest.py puts the repository root on the import path for pytest
get and put both mark a key as most-recently-used.Under load the cache is evicting the entry that was just inserted instead of the least-recently-used one. Hot data is being thrown away while cold data survives.
a is gone while b and c remain.Do not change the get recency behaviour as part of this ticket.
Reading a key does not mark it as recently used, so a frequently-read key can be evicted while keys that are never touched survive. Cache hit rates are worse than they should be.
get is marked most-recently-used and survives the next eviction.get is unchanged.Do not change the eviction direction as part of this ticket.
Re-putting an existing key updates its value but not its recency, so a freshly written key can be evicted before older, untouched ones.
get.Do not change the eviction direction as part of this ticket.
pytest tests/visible. Every shipped test fails on the starter code and passes once the bugs it covers are fixed.cache/ are submitted; the shipped tests in tests/visible run as they are.Adapted from treasure567/bloomberg-practice (round-2/ridgeline @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
lru-cache-wrong-eviction-and-stale-recency
Changes under src/ are evaluated.