From b505307f2f96463bc9ed2c8d3f1911d434723b94 Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Fri, 29 Aug 2025 16:07:04 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BC=98=E5=8C=96CacheDict=E7=B1=BB?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=94=AE=E5=AD=98=E5=9C=A8=E6=80=A7=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=92=8C=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=8F=AF=E8=AF=BB=E6=80=A7=E3=80=82=20(#2037?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/services/cache/cache_containers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zhenxun/services/cache/cache_containers.py b/zhenxun/services/cache/cache_containers.py index 4302a747..aad8878f 100644 --- a/zhenxun/services/cache/cache_containers.py +++ b/zhenxun/services/cache/cache_containers.py @@ -80,11 +80,7 @@ class CacheDict(Generic[T]): 返回: bool: 是否存在 """ - if key not in self._data: - return False - - # 检查是否过期 - return bool(self.expire_time(key)) + return False if key not in self._data else bool(self.expire_time(key)) def get(self, key: str, default: Any = None) -> T | None: """获取字典项,如果不存在返回默认值 @@ -96,8 +92,12 @@ class CacheDict(Generic[T]): 返回: Any: 字典值或默认值 """ - value = self[key] - return default if value is None else value + if value := self._data.get(key): + if self.expire_time(key): + return default + if not value: + return default + return default if value.value is None else value.value def set(self, key: str, value: Any, expire: int | None = None): """设置字典项