mirror of
https://github.com/TheSmallHanCat/sora2api.git
synced 2026-02-13 09:14:40 +08:00
feat: 支持缓存超时设置为-1表示永不自动删除
- file_cache.py: 清理任务检查 timeout=-1 时跳过删除 - admin.py: 后端验证允许 -1 值 - manage.html: 前端允许输入 -1,更新提示说明 - main.py: 启动时同步数据库缓存配置到 FileCache 实例
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -120,6 +120,9 @@ async def startup_event():
|
||||
config.set_cache_enabled(cache_config.cache_enabled)
|
||||
config.set_cache_timeout(cache_config.cache_timeout)
|
||||
config.set_cache_base_url(cache_config.cache_base_url or "")
|
||||
|
||||
# Sync cache timeout to file cache instance
|
||||
generation_handler.file_cache.set_timeout(cache_config.cache_timeout)
|
||||
|
||||
# Load generation configuration from database
|
||||
generation_config = await db.get_generation_config()
|
||||
|
||||
@@ -62,6 +62,10 @@ class FileCache:
|
||||
async def _cleanup_expired_files(self):
|
||||
"""Remove expired cache files"""
|
||||
try:
|
||||
# Skip cleanup if timeout is -1 (never delete)
|
||||
if self.default_timeout == -1:
|
||||
return
|
||||
|
||||
current_time = time.time()
|
||||
removed_count = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user