mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
pyd2
This commit is contained in:
parent
4eae5f5a85
commit
3161df4622
@ -1,15 +1,14 @@
|
|||||||
|
import inspect
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import inspect
|
|
||||||
from typing import Any, ClassVar, Generic, TypeVar
|
from typing import Any, ClassVar, Generic, TypeVar
|
||||||
|
|
||||||
|
import nonebot
|
||||||
from aiocache import Cache as AioCache
|
from aiocache import Cache as AioCache
|
||||||
|
|
||||||
# from aiocache.backends.redis import RedisCache
|
# from aiocache.backends.redis import RedisCache
|
||||||
from aiocache.base import BaseCache
|
from aiocache.base import BaseCache
|
||||||
from aiocache.serializers import JsonSerializer
|
from aiocache.serializers import JsonSerializer
|
||||||
import nonebot
|
|
||||||
from nonebot.compat import model_dump
|
from nonebot.compat import model_dump
|
||||||
from nonebot.utils import is_coroutine_callable
|
from nonebot.utils import is_coroutine_callable
|
||||||
from pydantic import BaseModel, PrivateAttr
|
from pydantic import BaseModel, PrivateAttr
|
||||||
@ -577,18 +576,21 @@ class CacheManager:
|
|||||||
expire: 过期时间(秒)
|
expire: 过期时间(秒)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def new(self, name: str, lazy_load: bool = True, expire: int = 600):
|
||||||
def wrapper(func: Callable):
|
def wrapper(func: Callable):
|
||||||
_name = name.upper()
|
_name = name.upper()
|
||||||
if _name in self._data:
|
if _name in self._data:
|
||||||
raise DbCacheException(f"缓存 {name} 已存在")
|
raise DbCacheException(f"缓存 {name} 已存在")
|
||||||
|
|
||||||
self._data[_name] = CacheData(
|
|
||||||
|
cache_data = CacheData(
|
||||||
name=_name,
|
name=_name,
|
||||||
func=func,
|
func=func,
|
||||||
expire=expire,
|
expire=expire,
|
||||||
lazy_load=lazy_load,
|
lazy_load=lazy_load,
|
||||||
_cache=self._cache,
|
|
||||||
)
|
)
|
||||||
|
cache_data._cache = self._cache
|
||||||
|
self._data[_name] = cache_data
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user