utils.py 文件源码

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

项目:taf 作者: taf3 项目源码 文件源码
def memoized(func):
    """A decorator to cache function's return value

    """
    cache = {}

    @functools.wraps(func)
    def wrapper(*args):
        if not isinstance(args, collections.Hashable):
            # args is not cacheable. just call the function.
            return func(*args)
        if args in cache:
            return cache[args]
        else:
            value = func(*args)
            cache[args] = value
            return value
    return wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号