mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-10 19:37:55 +00:00
refactor: 重构查询参数实现,替换旧的__init__初始化方式为dataclass+post_init
feat: 新增岗位编码字段与校验 fix: 修复批量删除提示、请求缓存、任务状态等逻辑 perf: 优化表格列展示,移除冗余ID列 build: 降级fastapi版本至0.115.2,更新依赖锁文件 docs: 补充部分代码注释与说明
This commit is contained in:
@@ -6,6 +6,7 @@ from functools import wraps
|
||||
from typing import Any
|
||||
|
||||
from redis.asyncio.client import Redis
|
||||
from starlette.responses import Response
|
||||
|
||||
_ENABLE: bool = True
|
||||
_EXPIRE: int = 300
|
||||
@@ -35,9 +36,19 @@ def cache(expire: int | None = None, namespace: str = "default"):
|
||||
key = _build_key(namespace, func, *args, **kwargs)
|
||||
cached = await _REDIS.get(key)
|
||||
if cached:
|
||||
return json.loads(cached)
|
||||
data = json.loads(cached)
|
||||
return Response(
|
||||
content=json.dumps(data, ensure_ascii=False),
|
||||
media_type="application/json; charset=utf-8",
|
||||
status_code=200,
|
||||
)
|
||||
result = await func(*args, **kwargs)
|
||||
await _REDIS.set(key, json.dumps(result), ex=expire or _EXPIRE)
|
||||
# 提取 Response 对象的 body 进行缓存
|
||||
if isinstance(result, Response):
|
||||
body = result.body
|
||||
else:
|
||||
body = json.dumps(result).encode()
|
||||
await _REDIS.set(key, body, ex=expire or _EXPIRE)
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user