summary refs log tree commit diff
path: root/synapse/util/caches/dictionary_cache.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2017-01-17 11:51:09 +0000
committerGitHub <noreply@github.com>2017-01-17 11:51:09 +0000
commitd11d7cdf875e524ce217ff3b091a07fb1c3b99ae (patch)
tree5f88266e2cc5c5ea5afe564d4488f65af3d227d1 /synapse/util/caches/dictionary_cache.py
parentMerge pull request #1810 from matrix-org/erikj/state_auth_splitout_split (diff)
parentTidy up test (diff)
downloadsynapse-d11d7cdf875e524ce217ff3b091a07fb1c3b99ae.tar.xz
Merge pull request #1815 from matrix-org/erikj/iter_cache_size
Optionally measure size of cache by sum of length of values
Diffstat (limited to 'synapse/util/caches/dictionary_cache.py')
-rw-r--r--synapse/util/caches/dictionary_cache.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/synapse/util/caches/dictionary_cache.py b/synapse/util/caches/dictionary_cache.py
index b0ca1bb79d..cb6933c61c 100644
--- a/synapse/util/caches/dictionary_cache.py
+++ b/synapse/util/caches/dictionary_cache.py
@@ -23,7 +23,9 @@ import logging
 logger = logging.getLogger(__name__)
 
 
-DictionaryEntry = namedtuple("DictionaryEntry", ("full", "value"))
+class DictionaryEntry(namedtuple("DictionaryEntry", ("full", "value"))):
+    def __len__(self):
+        return len(self.value)
 
 
 class DictionaryCache(object):
@@ -32,7 +34,7 @@ class DictionaryCache(object):
     """
 
     def __init__(self, name, max_entries=1000):
-        self.cache = LruCache(max_size=max_entries)
+        self.cache = LruCache(max_size=max_entries, size_callback=len)
 
         self.name = name
         self.sequence = 0