summary refs log tree commit diff
path: root/synapse/util/caches/response_cache.py
diff options
context:
space:
mode:
authorMathieu Velten <mathieuv@matrix.org>2022-12-15 17:04:23 +0100
committerGitHub <noreply@github.com>2022-12-15 16:04:23 +0000
commit54c012c5a8722725cf104fa6205f253b5b9b0192 (patch)
tree12f897e42b163460caebeade53722353008c5c3d /synapse/util/caches/response_cache.py
parentFix missing word in autotune sub-option description (#14674) (diff)
downloadsynapse-54c012c5a8722725cf104fa6205f253b5b9b0192.tar.xz
Make `handle_new_client_event` throws `PartialStateConflictError` (#14665)
Then adapts calling code to retry when needed so it doesn't 500
to clients.

Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r--synapse/util/caches/response_cache.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/synapse/util/caches/response_cache.py b/synapse/util/caches/response_cache.py
index a3eb5f741b..340e5e9145 100644
--- a/synapse/util/caches/response_cache.py
+++ b/synapse/util/caches/response_cache.py
@@ -167,12 +167,10 @@ class ResponseCache(Generic[KV]):
             # the should_cache bit, we leave it in the cache for now and schedule
             # its removal later.
             if self.timeout_sec and context.should_cache:
-                self.clock.call_later(
-                    self.timeout_sec, self._result_cache.pop, key, None
-                )
+                self.clock.call_later(self.timeout_sec, self.unset, key)
             else:
                 # otherwise, remove the result immediately.
-                self._result_cache.pop(key, None)
+                self.unset(key)
             return r
 
         # make sure we do this *after* adding the entry to result_cache,
@@ -181,6 +179,14 @@ class ResponseCache(Generic[KV]):
         result.addBoth(on_complete)
         return entry
 
+    def unset(self, key: KV) -> None:
+        """Remove the cached value for this key from the cache, if any.
+
+        Args:
+            key: key used to remove the cached value
+        """
+        self._result_cache.pop(key, None)
+
     async def wrap(
         self,
         key: KV,