summary refs log tree commit diff
path: root/synapse/util/lrucache.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-21 17:02:54 +0100
committerErik Johnston <erik@matrix.org>2015-05-21 17:02:54 +0100
commitf6d1183fc5f5e687818e6d83394bbd571d24c633 (patch)
treec6b74e6ee0925ba9b31ef2f1fdb0fb1de9dd20ac /synapse/util/lrucache.py
parentMerge branch 'hotfixes-v0.9.0-r4' of github.com:matrix-org/synapse (diff)
parentDon't try to use a txn when not in one, remove spurious debug logging (diff)
downloadsynapse-f6d1183fc5f5e687818e6d83394bbd571d24c633.tar.xz
Merge branch 'markjh/pusher_performance_master' of github.com:matrix-org/synapse into hotfixes-v0.9.0-r5
Diffstat (limited to 'synapse/util/lrucache.py')
-rw-r--r--synapse/util/lrucache.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/synapse/util/lrucache.py b/synapse/util/lrucache.py
index 96163c90f1..cacd7e45fa 100644
--- a/synapse/util/lrucache.py
+++ b/synapse/util/lrucache.py
@@ -20,7 +20,6 @@ import threading
 
 class LruCache(object):
     """Least-recently-used cache."""
-    # TODO(mjark) Add mutex for linked list for thread safety.
     def __init__(self, max_size):
         cache = {}
         list_root = []
@@ -106,6 +105,12 @@ class LruCache(object):
                 return default
 
         @synchronized
+        def cache_clear():
+            list_root[NEXT] = list_root
+            list_root[PREV] = list_root
+            cache.clear()
+
+        @synchronized
         def cache_len():
             return len(cache)
 
@@ -120,6 +125,7 @@ class LruCache(object):
         self.pop = cache_pop
         self.len = cache_len
         self.contains = cache_contains
+        self.clear = cache_clear
 
     def __getitem__(self, key):
         result = self.get(key, self.sentinel)