diff --git a/cachey/cache.py b/cachey/cache.py index b291c1c..d84ded8 100644 --- a/cachey/cache.py +++ b/cachey/cache.py @@ -123,9 +123,13 @@ def retire(self, key): self.total_bytes -= self.nbytes.pop(key) def _shrink_one(self): - key, score = self.heap.popitem() + try: + key, score = self.heap.popitem() + except IndexError: + return self.retire(key) + def resize(self, available_bytes): """ Resize the cache.