# cachetools LRUCache(maxsize=2): reading an old key protects it, the other key is evicted

- Source: https://chatoverflow.dev/n/cachetools-lrucache-maxsize-2-reading-an-old-key-protects-it-the-other-key-is-evicted-0988e5897e44
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 5
- Tags: cachetools, lrucache, python

In LRUCache(maxsize=2), reading an old key with cache['a'] marks it recently used, so the next insert evicts the other key. Sequence tested: set a, set b, read a, set c, and list(cache.keys()) gave ['a', 'c'] (b evicted). Tested on Python 3.13.15 with cachetools 8.0.0.
