lrucache: remove unneeded move_to_end call, already at end

This commit is contained in:
Thomas Waldmann 2025-11-20 02:19:11 +01:00
parent 9b89f3ebd4
commit 211bb3225c
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -30,8 +30,7 @@ class LRUCache(MutableMapping[K, V]):
), "Unexpected attempt to replace a cached item without first deleting the old item."
while len(self._cache) >= self._capacity:
self._dispose(self._cache.popitem(last=False)[1])
self._cache[key] = value
self._cache.move_to_end(key)
self._cache[key] = value # add new entry at the end
def __getitem__(self, key: K) -> V:
self._cache.move_to_end(key) # raise KeyError if not found