Merge pull request #9587 from ThomasWaldmann/fix-lrucache-1.4

LRUCache fixes 1.4
This commit is contained in:
TW 2026-05-04 21:32:08 +02:00 committed by GitHub
commit 164e9d0cb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,10 +12,10 @@ class LRUCache:
assert key not in self._cache, (
"Unexpected attempt to replace a cached item,"
" without first deleting the old item.")
self._cache[key] = value
self._lru.append(key)
while len(self._lru) > self._capacity:
del self[self._lru[0]]
self._cache[key] = value
def __getitem__(self, key):
value = self._cache[key] # raise KeyError if not found
@ -49,6 +49,7 @@ class LRUCache:
for value in self._cache.values():
self._dispose(value)
self._cache.clear()
self._lru.clear()
def items(self):
return self._cache.items()