def get(self, key, default=None, acquire_lock=True):
"""
Fetch a given key from the cache. If the key does not exist, return
default, which itself defaults to None.
"""
key = self.make_key(key)
pickled = None
with (self._lock.reader() if acquire_lock else dummy()):
if not self._has_expired(key):
pickled = self._cache[key]
if pickled is not None:
try:
return pickle.loads(pickled)
except pickle.PickleError:
return default
with (self._lock.writer() if acquire_lock else dummy()):
try:
del self._cache[key]
del self._expire_info[key]
except KeyError:
pass
return default
评论列表
文章目录