feat: 支持缓存超时设置为-1表示永不自动删除

- file_cache.py: 清理任务检查 timeout=-1 时跳过删除
- admin.py: 后端验证允许 -1 值
- manage.html: 前端允许输入 -1,更新提示说明
- main.py: 启动时同步数据库缓存配置到 FileCache 实例
This commit is contained in:
axibayuit
2025-12-24 01:31:10 +08:00
parent 2f6fc345a9
commit 306ba90100
4 changed files with 18 additions and 8 deletions

View File

@@ -723,11 +723,13 @@ async def update_cache_timeout(
):
"""Update cache timeout"""
try:
if request.timeout < 60:
raise HTTPException(status_code=400, detail="Cache timeout must be at least 60 seconds")
# Allow -1 for never delete, otherwise must be between 60-86400
if request.timeout != -1:
if request.timeout < 60:
raise HTTPException(status_code=400, detail="Cache timeout must be at least 60 seconds or -1 for never delete")
if request.timeout > 86400:
raise HTTPException(status_code=400, detail="Cache timeout cannot exceed 24 hours (86400 seconds)")
if request.timeout > 86400:
raise HTTPException(status_code=400, detail="Cache timeout cannot exceed 24 hours (86400 seconds)")
# Update in-memory config
config.set_cache_timeout(request.timeout)
@@ -739,9 +741,10 @@ async def update_cache_timeout(
if generation_handler:
generation_handler.file_cache.set_timeout(request.timeout)
timeout_msg = "never delete" if request.timeout == -1 else f"{request.timeout} seconds"
return {
"success": True,
"message": f"Cache timeout updated to {request.timeout} seconds",
"message": f"Cache timeout updated to {timeout_msg}",
"timeout": request.timeout
}
except HTTPException: