mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-23 01:55:53 +03:00
Give LruCache a __len__, so that len(cache) works
This commit is contained in:
parent
1af1c45dc0
commit
027fd1242c
1 changed files with 7 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue