Fix multi level cache key build and usage (#1066)

* Fix multi level cache key build and usage

* Update build cache key
This commit is contained in:
Wu Clan
2026-02-06 13:42:13 +08:00
committed by GitHub
parent 95aebe1ceb
commit 4d457b2215
5 changed files with 26 additions and 83 deletions
@@ -20,6 +20,7 @@ class ConfigService:
"""参数配置服务类"""
@staticmethod
@cached(settings.CACHE_CONFIG_REDIS_PREFIX, key='pk')
async def get(*, db: AsyncSession, pk: int) -> Config:
"""
获取参数配置详情
@@ -34,10 +35,7 @@ class ConfigService:
return config
@staticmethod
@cached(
settings.CACHE_CONFIG_REDIS_PREFIX,
key_builder=lambda *, db, type: f'type:{type}',
)
@cached(settings.CACHE_CONFIG_REDIS_PREFIX, key='type')
async def get_all(*, db: AsyncSession, type: str | None) -> Sequence[Config | None]:
"""
获取所有参数配置
@@ -62,7 +60,6 @@ class ConfigService:
return await paging_data(db, config_select)
@staticmethod
@cache_invalidate(settings.CACHE_CONFIG_REDIS_PREFIX)
async def create(*, db: AsyncSession, obj: CreateConfigParam) -> None:
"""
创建参数配置
@@ -17,6 +17,7 @@ class DictDataService:
"""字典数据服务类"""
@staticmethod
@cached(settings.CACHE_DICT_REDIS_PREFIX, key='pk')
async def get(*, db: AsyncSession, pk: int) -> DictData:
"""
获取字典数据详情
@@ -49,10 +50,6 @@ class DictDataService:
return dict_datas
@staticmethod
@cached(
settings.CACHE_DICT_REDIS_PREFIX,
key_builder=lambda *, db: 'all',
)
async def get_all(*, db: AsyncSession) -> Sequence[DictData]:
"""
获取所有字典数据
@@ -94,7 +91,6 @@ class DictDataService:
return await paging_data(db, dict_data_select)
@staticmethod
@cache_invalidate(settings.CACHE_DICT_REDIS_PREFIX)
async def create(*, db: AsyncSession, obj: CreateDictDataParam) -> None:
"""
创建字典数据