summary refs log tree commit diff
path: root/synapse/util/caches/lrucache.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2016-01-22 12:10:33 +0000
committerDavid Baker <dave@matrix.org>2016-01-22 12:10:33 +0000
commit10f76dc5da47c49a4191d8113b3c0615224eb9fd (patch)
tree07d2113ec55cf1a86f1b64b37767c434d8b4eb5c /synapse/util/caches/lrucache.py
parentAdd __contains__ (diff)
downloadsynapse-10f76dc5da47c49a4191d8113b3c0615224eb9fd.tar.xz
Make LRU cache not default to treecache & add options to use it
Diffstat (limited to 'synapse/util/caches/lrucache.py')
-rw-r--r--synapse/util/caches/lrucache.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/synapse/util/caches/lrucache.py b/synapse/util/caches/lrucache.py
index 0feceb298a..23e86ec110 100644
--- a/synapse/util/caches/lrucache.py
+++ b/synapse/util/caches/lrucache.py
@@ -17,8 +17,6 @@
 from functools import wraps
 import threading
 
-from synapse.util.caches.treecache import TreeCache
-
 
 def enumerate_leaves(node, depth):
     if depth == 0:
@@ -31,8 +29,8 @@ def enumerate_leaves(node, depth):
 
 class LruCache(object):
     """Least-recently-used cache."""
-    def __init__(self, max_size, keylen):
-        cache = TreeCache()
+    def __init__(self, max_size, keylen, cache_type=dict):
+        cache = cache_type()
         self.size = 0
         list_root = []
         list_root[:] = [list_root, list_root, None, None]
@@ -124,6 +122,9 @@ class LruCache(object):
 
         @synchronized
         def cache_del_multi(key):
+            """
+            This will only work if constructed with cache_type=TreeCache
+            """
             popped = cache.pop(key)
             if popped is None:
                 return