-
-
Notifications
You must be signed in to change notification settings - Fork 184
Closed
Labels
Description
Before reporting a bug, please make sure you have the latest cachetools version installed:
pip install --upgrade cachetools
Describe the bug
For extending a class, the docs say all cache implementations call popitem() to evict items from the cache and indicate that overriding the popitem() can catch expiration from any class.
This does not work with TTLCache.
Expected result
Overriding popitem() should be called when an item is expired.
Actual result
The popitem() method is not called.
Reproduction steps
import time
from cachetools import TTLCache
class MyCache(TTLCache):
def popitem(self):
key, value = super().popitem()
print('Key "%s" evicted with value "%s"' % (key, value))
return key, value
c = MyCache(maxsize=20, ttl=2)
c["a"] = 1
time.sleep(1)
c["b"] = 2
time.sleep(4)
c["c"] = 3