mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
test1
This commit is contained in:
parent
f672ef47eb
commit
cd9c18291e
@ -568,30 +568,33 @@ class CacheManager:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"初始化缓存 {name} 失败: {e}")
|
logger.error(f"初始化缓存 {name} 失败: {e}")
|
||||||
|
|
||||||
def new(self, name: str, lazy_load: bool = True, expire: int = 600):
|
def new(self, name: str, lazy_load: bool = True, expire: int = 600):
|
||||||
"""注册新缓存
|
"""注册新缓存
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
name: 缓存名称
|
name: 缓存名称
|
||||||
lazy_load: 是否延迟加载,默认为True。为False时会在程序启动时自动加载
|
lazy_load: 是否延迟加载,默认为True。为False时会在程序启动时自动加载
|
||||||
expire: 过期时间(秒)
|
expire: 过期时间(秒)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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(
|
# 先创建 CacheData 实例(不传入 _cache)
|
||||||
name=_name,
|
cache_data = CacheData(
|
||||||
func=func,
|
name=_name,
|
||||||
expire=expire,
|
func=func,
|
||||||
lazy_load=lazy_load,
|
expire=expire,
|
||||||
_cache=self._cache,
|
lazy_load=lazy_load,
|
||||||
)
|
)
|
||||||
return func
|
# 然后手动设置 _cache 属性
|
||||||
|
cache_data._cache = self._cache
|
||||||
|
self._data[_name] = cache_data
|
||||||
|
return func
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def listener(self, name: str):
|
def listener(self, name: str):
|
||||||
"""创建缓存监听器"""
|
"""创建缓存监听器"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user