summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2016-08-03 11:12:47 +0100
committerMark Haines <mark.haines@matrix.org>2016-08-03 11:12:47 +0100
commit921f17f93810ac07fd5d15494882db78fdcf3e3c (patch)
treebd4f29ec888a4e445654688e0f6da994be899a63 /synapse/util
parentE2E keys: Make federation query share code with client query (diff)
parentFactor out some of the code shared between the sytest scripts (#974) (diff)
downloadsynapse-921f17f93810ac07fd5d15494882db78fdcf3e3c.tar.xz
Merge branch 'develop' into rav/refactor_device_query
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/response_cache.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/synapse/util/caches/response_cache.py b/synapse/util/caches/response_cache.py
index 36686b479e..00af539880 100644
--- a/synapse/util/caches/response_cache.py
+++ b/synapse/util/caches/response_cache.py
@@ -24,9 +24,12 @@ class ResponseCache(object):
     used rather than trying to compute a new response.
     """
 
-    def __init__(self):
+    def __init__(self, hs, timeout_ms=0):
         self.pending_result_cache = {}  # Requests that haven't finished yet.
 
+        self.clock = hs.get_clock()
+        self.timeout_sec = timeout_ms / 1000.
+
     def get(self, key):
         result = self.pending_result_cache.get(key)
         if result is not None:
@@ -39,7 +42,13 @@ class ResponseCache(object):
         self.pending_result_cache[key] = result
 
         def remove(r):
-            self.pending_result_cache.pop(key, None)
+            if self.timeout_sec:
+                self.clock.call_later(
+                    self.timeout_sec,
+                    self.pending_result_cache.pop, key, None,
+                )
+            else:
+                self.pending_result_cache.pop(key, None)
             return r
 
         result.addBoth(remove)