summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-04-10 23:14:47 +0100
committerRichard van der Hoff <richard@matrix.org>2018-04-10 23:14:47 +0100
commitb3384232a031cc209fb5f0e085bc073a220448be (patch)
tree470435a5ae98030391c40551e835f45e0fa51ec0 /synapse/util
parentMerge pull request #3061 from NotAFile/add-some-byte-strings (diff)
downloadsynapse-b3384232a031cc209fb5f0e085bc073a220448be.tar.xz
Add metrics for ResponseCache
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/response_cache.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/synapse/util/caches/response_cache.py b/synapse/util/caches/response_cache.py
index 00af539880..7f68289723 100644
--- a/synapse/util/caches/response_cache.py
+++ b/synapse/util/caches/response_cache.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 from synapse.util.async import ObservableDeferred
+from synapse.util.caches import metrics as cache_metrics
 
 
 class ResponseCache(object):
@@ -24,17 +25,28 @@ class ResponseCache(object):
     used rather than trying to compute a new response.
     """
 
-    def __init__(self, hs, timeout_ms=0):
+    def __init__(self, hs, name, timeout_ms=0):
         self.pending_result_cache = {}  # Requests that haven't finished yet.
 
         self.clock = hs.get_clock()
         self.timeout_sec = timeout_ms / 1000.
 
+        self._metrics = cache_metrics.register_cache(
+            "response_cache",
+            size_callback=lambda: self.size(),
+            cache_name=name,
+        )
+
+    def size(self):
+        return len(self.pending_result_cache)
+
     def get(self, key):
         result = self.pending_result_cache.get(key)
         if result is not None:
+            self._metrics.inc_hits()
             return result.observe()
         else:
+            self._metrics.inc_misses()
             return None
 
     def set(self, key, deferred):