From 5650098a61c5a319dcd21dcf6a94a781691c93a8 Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Sat, 11 Apr 2015 01:49:57 -0700 Subject: [PATCH] fixes #21 - self.root was not being correctly updated, so the list never rotated out entries! this has a very simple test to demonstrate the issue is closed. more tests are needed. --- boltons/cacheutils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/boltons/cacheutils.py b/boltons/cacheutils.py index 72b71cc..84d23d5 100644 --- a/boltons/cacheutils.py +++ b/boltons/cacheutils.py @@ -133,7 +133,7 @@ class LRU(dict): oldroot[KEY] = key oldroot[VALUE] = value # prevent ref counts going to zero during update - root = oldroot[NEXT] + self.root = root = oldroot[NEXT] oldkey, oldresult = root[KEY], root[VALUE] root[KEY] = root[VALUE] = None # Now update the cache dictionary. @@ -433,8 +433,15 @@ def cached(cache, typed=False): return cached_func_decorator +def test_21(): + cache = LRU(max_size=3) + for i in xrange(4): + cache[i] = i + if __name__ == '__main__': + test_21() + def _test_lri(): import string bc = LRI(10, on_miss=lambda k: k.upper())