summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/storage/_base.py3
-rw-r--r--tests/storage/test__base.py7
2 files changed, 8 insertions, 2 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 42edb56c36..da698cb3b8 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -75,8 +75,7 @@ def cached(max_entries=1000):
             defer.returnValue(ret)
 
         def invalidate(key):
-            if key in cache:
-                del cache[key]
+            cache.pop(key, None)
 
         wrapped.invalidate = invalidate
         wrapped.prefill = prefill
diff --git a/tests/storage/test__base.py b/tests/storage/test__base.py
index fb306cb784..55d22f665a 100644
--- a/tests/storage/test__base.py
+++ b/tests/storage/test__base.py
@@ -66,6 +66,13 @@ class CacheDecoratorTestCase(unittest.TestCase):
 
         self.assertEquals(callcount[0], 2)
 
+    def test_invalidate_missing(self):
+        @cached()
+        def func(self, key):
+            return key
+
+        func.invalidate("what")
+
     @defer.inlineCallbacks
     def test_max_entries(self):
         callcount = [0]