mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Implement the 'key in dict' test for LruCache()
This commit is contained in:
parent
7ab9f91a60
commit
d6b3ea75d4
@ -90,12 +90,16 @@ class LruCache(object):
|
|||||||
def cache_len():
|
def cache_len():
|
||||||
return len(cache)
|
return len(cache)
|
||||||
|
|
||||||
|
def cache_contains(key):
|
||||||
|
return key in cache
|
||||||
|
|
||||||
self.sentinel = object()
|
self.sentinel = object()
|
||||||
self.get = cache_get
|
self.get = cache_get
|
||||||
self.set = cache_set
|
self.set = cache_set
|
||||||
self.setdefault = cache_set_default
|
self.setdefault = cache_set_default
|
||||||
self.pop = cache_pop
|
self.pop = cache_pop
|
||||||
self.len = cache_len
|
self.len = cache_len
|
||||||
|
self.contains = cache_contains
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
result = self.get(key, self.sentinel)
|
result = self.get(key, self.sentinel)
|
||||||
@ -114,3 +118,6 @@ class LruCache(object):
|
|||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return self.len()
|
return self.len()
|
||||||
|
|
||||||
|
def __contains__(self, key):
|
||||||
|
return self.contains(key)
|
||||||
|
Loading…
Reference in New Issue
Block a user