forked from MirrorHub/synapse
Correctly match 'dict.pop' api
This commit is contained in:
parent
8ea887856c
commit
4f3e3ac192
1 changed files with 11 additions and 3 deletions
|
@ -98,10 +98,18 @@ class ExpiringCache(object):
|
||||||
|
|
||||||
return entry.value
|
return entry.value
|
||||||
|
|
||||||
def pop(self, key, default=None):
|
def pop(self, key, default=SENTINEL):
|
||||||
value = self._cache.pop(key, SENTINEL)
|
"""Removes and returns the value with the given key from the cache.
|
||||||
|
|
||||||
|
If the key isn't in the cache then `default` will be returned if
|
||||||
|
specified, otherwise `KeyError` will get raised.
|
||||||
|
|
||||||
|
Identical functionality to `dict.pop(..)`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
value = self._cache.pop(key, default)
|
||||||
if value is SENTINEL:
|
if value is SENTINEL:
|
||||||
return default
|
raise KeyError(key)
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue