cache.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Weeds 作者: seamile 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号