summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorJason Little <realtyem@gmail.com>2023-08-01 07:10:49 -0500
committerGitHub <noreply@github.com>2023-08-01 08:10:49 -0400
commit7cbb2a00d1ed07d42c6fa1fb226db512cd2a6b90 (patch)
tree13d5ca110c536b7aa0a96b60633122c760165f7f /synapse/util
parentMerge branch 'master' into develop (diff)
downloadsynapse-7cbb2a00d1ed07d42c6fa1fb226db512cd2a6b90.tar.xz
Add metrics tracking for eviction to ResponseCache (#16028)
Track whether the ResponseCache is evicting due to invalidation
or due to time.
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/response_cache.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/synapse/util/caches/response_cache.py b/synapse/util/caches/response_cache.py
index 340e5e9145..0cb46700a9 100644
--- a/synapse/util/caches/response_cache.py
+++ b/synapse/util/caches/response_cache.py
@@ -36,7 +36,7 @@ from synapse.logging.opentracing import (
 )
 from synapse.util import Clock
 from synapse.util.async_helpers import AbstractObservableDeferred, ObservableDeferred
-from synapse.util.caches import register_cache
+from synapse.util.caches import EvictionReason, register_cache
 
 logger = logging.getLogger(__name__)
 
@@ -167,7 +167,7 @@ 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.unset, key)
+                self.clock.call_later(self.timeout_sec, self._entry_timeout, key)
             else:
                 # otherwise, remove the result immediately.
                 self.unset(key)
@@ -185,6 +185,12 @@ class ResponseCache(Generic[KV]):
         Args:
             key: key used to remove the cached value
         """
+        self._metrics.inc_evictions(EvictionReason.invalidation)
+        self._result_cache.pop(key, None)
+
+    def _entry_timeout(self, key: KV) -> None:
+        """For the call_later to remove from the cache"""
+        self._metrics.inc_evictions(EvictionReason.time)
         self._result_cache.pop(key, None)
 
     async def wrap(