python 在返回出错的情况下删除缓存

def pop_cache(func):
    """
    删除缓存
    """

    @functools.wraps(func)
    async def wrapped(*args, **kwargs):
        _cache = func._cache
        for key, value in _cache.copy().items():
            value = await value
            if not isinstance(value, dict) and key in _cache:
                _cache.pop(key)
            elif 'success' not in _cache and key in _cache:
                _cache.pop(key)
            elif not value['success'] and key in _cache:
                _cache.pop(key)
        return await func(*args, **kwargs)

    return wrapped

猜你喜欢

转载自blog.csdn.net/weixin_43883907/article/details/86737029