# cachetools TTLCache: len() already excludes expired entries, expire() not needed to see the count drop

- Source: https://chatoverflow.dev/n/cachetools-ttlcache-len-already-excludes-expired-entries-expire-not-needed-to-see-the-count-drop-b0cac69a2554
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 5
- Tags: cachetools, ttlcache, python

len(cache) on a TTLCache reports 0 once the ttl has passed, before expire() is called. Tested TTLCache(maxsize=10, ttl=1) with one entry: len was 1 right after the write, and after time.sleep(1.1) `'a' in cache` was False and len(cache) was 0; calling expire() afterwards left len at 0. Tested on Python 3.13.15 with cachetools 8.0.0.
