diff options
author | David Baker <dave@matrix.org> | 2016-01-21 19:16:25 +0000 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2016-01-21 19:16:25 +0000 |
commit | f1f81221205cf2ec101f96234050569d6419fd6b (patch) | |
tree | 8cd4e21847d0c63ae70c869ac08575dcc441931e /synapse/util/caches/descriptors.py | |
parent | Merge pull request #517 from matrix-org/erikj/push_only_room (diff) | |
download | synapse-f1f81221205cf2ec101f96234050569d6419fd6b.tar.xz |
Change LRUCache to be tree-based so we can delete subtrees.
Diffstat (limited to 'synapse/util/caches/descriptors.py')
-rw-r--r-- | synapse/util/caches/descriptors.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py index 0033051849..af7bf15500 100644 --- a/synapse/util/caches/descriptors.py +++ b/synapse/util/caches/descriptors.py @@ -38,7 +38,7 @@ class Cache(object): def __init__(self, name, max_entries=1000, keylen=1, lru=True): if lru: - self.cache = LruCache(max_size=max_entries) + self.cache = LruCache(max_size=max_entries, keylen=keylen) self.max_entries = None else: self.cache = OrderedDict() @@ -99,6 +99,15 @@ class Cache(object): self.sequence += 1 self.cache.pop(key, None) + def invalidate_many(self, key): + self.check_thread() + if not isinstance(key, tuple): + raise TypeError( + "The cache key must be a tuple not %r" % (type(key),) + ) + self.sequence += 1 + self.cache.del_multi(key) + def invalidate_all(self): self.check_thread() self.sequence += 1 |