BuildMidBackendAuto-graded
Fix a cache that evicts recently used keys
Under load the cache throws out the keys services are reading and keeps cold ones; make eviction true LRU.LRUCache(capacity) is meant to evict the least recently used entry when it's full. In production it keeps throwing out the keys services are reading and holding on to cold ones. Make eviction true LRU, with reads and writes both counting as a use, and keep get and put O(1). Build it yourself; don't wrap functools.lru_cache.35 min
python
You're done when
- When the cache is full, it evicts the entry used least recently.
- Reading a key with
getcounts as a use, so a key you just read is not the next one evicted. - Writing a key with
put, including updating one already in the cache, counts as a use too. getandputstay just as fast when the cache holds tens of thousands of entries as when it holds a few hundred.- Every read returns the expected hit or miss across a reference sequence of reads and writes.
What it measures
Data structures and algorithmsPairing a map with an ordering structure so lookup, update and eviction all run in constant time.
Class designKeeping two internal structures in sync behind a small `get`/`put` interface.
Testing edge casesFinding the access pattern that shows the wrong eviction, beyond the cases that already pass.
Your environment
Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards
Start this lab
35 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo