This commit is contained in:
ManyManyTomato 2025-07-05 13:20:58 +00:00
parent cd9c18291e
commit 994d6ff271

View File

@ -568,7 +568,7 @@ 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):
"""注册新缓存 """注册新缓存
参数: 参数:
@ -582,16 +582,13 @@ def new(self, name: str, lazy_load: bool = True, expire: int = 600):
if _name in self._data: if _name in self._data:
raise DbCacheException(f"缓存 {name} 已存在") raise DbCacheException(f"缓存 {name} 已存在")
# 先创建 CacheData 实例(不传入 _cache 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 属性
cache_data._cache = self._cache
self._data[_name] = cache_data
return func return func
return wrapper return wrapper