From bafd35cafa20bbe308921249175ea7d999e5ce06 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sat, 27 Feb 2016 20:23:44 -0500 Subject: [PATCH] Tentative fix for LRUcache bug (with Python 2.7.11?), reported by "andrew1883". --- lrucache.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lrucache.py b/lrucache.py index ca8733d..aa05d3a 100644 --- a/lrucache.py +++ b/lrucache.py @@ -144,7 +144,8 @@ class LRUCache(object): heapify(self.__heap) else: # size may have been reset, so we loop - while len(self.__heap) >= self.size: + overage = len(self.__heap) - self.size + 1 + for i in xrange(overage): lru = heappop(self.__heap) del self.__dict[lru.key] node = self.__Node(key, obj, time.time()) @@ -181,7 +182,8 @@ class LRUCache(object): object.__setattr__(self, name, value) # automagically shrink heap on resize if name == 'size': - while len(self.__heap) > value: + overage = len(self.__heap) - value + for i in xrange(overage): lru = heappop(self.__heap) del self.__dict[lru.key] -- 2.11.4.GIT