import{_ as i,c as a,o as n,ae as e}from"./chunks/framework.BHrE6nLq.js";const o=JSON.parse('{"title":"decos","description":"","frontmatter":{"title":"decos","order":100},"headers":[],"relativePath":"en/dev/api/cache/decos.md","filePath":"en/dev/api/cache/decos.md","lastUpdated":null}'),t={name:"en/dev/api/cache/decos.md"};function h(p,s,l,k,r,d){return n(),a("div",null,s[0]||(s[0]=[e(`

Module nonebot_plugin_marshoai.cache.decos


func from_cache(key)

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

Source code or View on 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)

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

Source code or View on 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
`,9)]))}const E=i(t,[["render",h]]);export{o as __pageData,E as default};