Input
cache = LRUCache(2); cache.put('a', 1); cache.put('b', 2); cache.put('c', 3)Output
cache.get('a') == None (a was evicted as LRU); cache.get('b') == 2; cache.get('c') == 3Capacity=2, three inserts. 'a' is the oldest, so it goes.
An LRU cache from a production service is leaking memory and serving stale entries. Basic functional tests still pass — `cache.put('a', 1); cache.get('a')` returns `1` — but under stress the internal dictionary grows un...
lru_cache.pyEditable startercache = LRUCache(2); cache.put('a', 1); cache.put('b', 2); cache.put('c', 3)cache.get('a') == None (a was evicted as LRU); cache.get('b') == 2; cache.get('c') == 3Capacity=2, three inserts. 'a' is the oldest, so it goes.
cache = LRUCache(2); cache.get('x'); cache.get('y'); len(cache._dict)0
Misses must not create entries. A cache that does is leaking.
How would you add a TTL to each entry so that entries also expire by age, not just by recency?