memoize_cache.py 文件源码

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

项目:montage 作者: storyful 项目源码 文件源码
def get_or_set(self, fn, *args, **kwargs):
        """
            Wraps `fn` and caches the response

            Cache key varys by all *args and **kwargs
        """
        timeout = kwargs.pop("timeout", None)
        message_type = kwargs.pop("message_type", None)
        key = self.create_key(fn, args, kwargs)

        obj = self.get_by_key(key, message_type=message_type)

        if obj is None:
            obj = fn(*args, **kwargs)
            self.add_by_key(
                key, obj, timeout=timeout, message_type=message_type)

        return obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号