mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-08-01 22:59:53 +00:00
pre implement cache
This commit is contained in:
15
nonebot_plugin_marshoai/decos.py
Normal file
15
nonebot_plugin_marshoai/decos.py
Normal file
@ -0,0 +1,15 @@
|
||||
from .instances import cache
|
||||
|
||||
|
||||
def from_cache(key):
|
||||
def decorator(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
cached = cache.get(key)
|
||||
if cached:
|
||||
return cached
|
||||
else:
|
||||
result = func(*args, **kwargs)
|
||||
cache.set(key, result)
|
||||
return result
|
||||
|
||||
return wrapper
|
Reference in New Issue
Block a user