Skip to content
Snippets Groups Projects
Commit f53fcbce authored by Paul "LeoNerd" Evans's avatar Paul "LeoNerd" Evans
Browse files

Use cache.pop() instead of a separate membership test + del []

parent 27080698
Branches
Tags
No related merge requests found
...@@ -75,8 +75,7 @@ def cached(max_entries=1000): ...@@ -75,8 +75,7 @@ def cached(max_entries=1000):
defer.returnValue(ret) defer.returnValue(ret)
def invalidate(key): def invalidate(key):
if key in cache: cache.pop(key, None)
del cache[key]
wrapped.invalidate = invalidate wrapped.invalidate = invalidate
wrapped.prefill = prefill wrapped.prefill = prefill
......
...@@ -66,6 +66,13 @@ class CacheDecoratorTestCase(unittest.TestCase): ...@@ -66,6 +66,13 @@ class CacheDecoratorTestCase(unittest.TestCase):
self.assertEquals(callcount[0], 2) self.assertEquals(callcount[0], 2)
def test_invalidate_missing(self):
@cached()
def func(self, key):
return key
func.invalidate("what")
@defer.inlineCallbacks @defer.inlineCallbacks
def test_max_entries(self): def test_max_entries(self):
callcount = [0] callcount = [0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment