summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-09-21 14:55:47 +0100
committerErik Johnston <erik@matrix.org>2018-09-21 14:56:12 +0100
commitfdd1a62e8d09ddccbe685fe7d7840990a9c06241 (patch)
tree0ef1a439a2a7b73ca4f53780bf5978f92b31f64a /synapse/util
parentMake ExpiringCache slightly more performant (diff)
downloadsynapse-fdd1a62e8d09ddccbe685fe7d7840990a9c06241.tar.xz
Add a five minute cache to get_destination_retry_timings
Hopefully helps with #3931
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/expiringcache.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/synapse/util/caches/expiringcache.py b/synapse/util/caches/expiringcache.py
index 48ca2d634d..346669e4ce 100644
--- a/synapse/util/caches/expiringcache.py
+++ b/synapse/util/caches/expiringcache.py
@@ -24,6 +24,9 @@ from synapse.util.caches import register_cache
 logger = logging.getLogger(__name__)
 
 
+SENTINEL = object()
+
+
 class ExpiringCache(object):
     def __init__(self, cache_name, clock, max_len=0, expiry_ms=0,
                  reset_expiry_on_get=False, iterable=False):
@@ -102,6 +105,16 @@ class ExpiringCache(object):
 
         return entry.value
 
+    def pop(self, key, default=None):
+        value = self._cache.pop(key, SENTINEL)
+        if value is SENTINEL:
+            return default
+
+        if self.iterable:
+            self._size_estimate -= len(value.value)
+
+        return value
+
     def __contains__(self, key):
         return key in self._cache