Skip to content

模块 nonebot_plugin_marshoai.cache.decos


func from_cache(key)

说明: 当缓存中有数据时,直接返回缓存中的数据,否则执行函数并将结果存入缓存

源代码在GitHub上查看
python
def from_cache(key):

    def decorator(func):

        async def wrapper(*args, **kwargs):
            cached = cache.get(key)
            if cached:
                return cached
            else:
                result = await func(*args, **kwargs)
                cache.set(key, result)
                return result
        return wrapper
    return decorator

func update_to_cache(key)

说明: 执行函数并将结果存入缓存

源代码在GitHub上查看
python
def update_to_cache(key):

    def decorator(func):

        async def wrapper(*args, **kwargs):
            result = await func(*args, **kwargs)
            cache.set(key, result)
            return result
        return wrapper
    return decorator