summary refs log tree commit diff
path: root/synapse/util/caches/expiringcache.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-10-01 12:25:27 +0100
committerErik Johnston <erik@matrix.org>2018-10-01 12:25:27 +0100
commit4f3e3ac192f2c5ff37198f50af99bc8fbd57beca (patch)
treee1e1eeefe51720f4d74602e2fe9a19bb811984e9 /synapse/util/caches/expiringcache.py
parentDon't update eviction metrics on explicit removal (diff)
downloadsynapse-4f3e3ac192f2c5ff37198f50af99bc8fbd57beca.tar.xz
Correctly match 'dict.pop' api
Diffstat (limited to '')
-rw-r--r--synapse/util/caches/expiringcache.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/synapse/util/caches/expiringcache.py b/synapse/util/caches/expiringcache.py
index f2f55ba6c9..f369780277 100644
--- a/synapse/util/caches/expiringcache.py
+++ b/synapse/util/caches/expiringcache.py
@@ -98,10 +98,18 @@ class ExpiringCache(object):
 
         return entry.value
 
-    def pop(self, key, default=None):
-        value = self._cache.pop(key, SENTINEL)
+    def pop(self, key, default=SENTINEL):
+        """Removes and returns the value with the given key from the cache.
+
+        If the key isn't in the cache then `default` will be returned if
+        specified, otherwise `KeyError` will get raised.
+
+        Identical functionality to `dict.pop(..)`.
+        """
+
+        value = self._cache.pop(key, default)
         if value is SENTINEL:
-            return default
+            raise KeyError(key)
 
         return value