diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-04 17:32:28 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-04 17:32:28 +0000 |
commit | 027fd1242cfaf3ae26856f94c01d2b7c04705172 (patch) | |
tree | e280048631751d68d6f986b2a99a502a141fa479 /synapse | |
parent | Merge pull request #99 from matrix-org/schema_versioning (diff) | |
download | synapse-027fd1242cfaf3ae26856f94c01d2b7c04705172.tar.xz |
Give LruCache a __len__, so that len(cache) works
Diffstat (limited to '')
-rw-r--r-- | synapse/util/lrucache.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/synapse/util/lrucache.py b/synapse/util/lrucache.py index a45c673d32..f115f50e50 100644 --- a/synapse/util/lrucache.py +++ b/synapse/util/lrucache.py @@ -88,11 +88,15 @@ class LruCache(object): else: return default + def cache_len(): + return len(cache) + self.sentinel = object() self.get = cache_get self.set = cache_set self.setdefault = cache_set_default self.pop = cache_pop + self.len = cache_len def __getitem__(self, key): result = self.get(key, self.sentinel) @@ -108,3 +112,6 @@ class LruCache(object): result = self.pop(key, self.sentinel) if result is self.sentinel: raise KeyError() + + def __len__(self): + return self.len() |