Give LruCache a __len__, so that len(cache) works

This commit is contained in:
Paul "LeoNerd" Evans 2015-03-04 17:32:28 +00:00
parent 1af1c45dc0
commit 027fd1242c

View file

@ -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()