diff --git a/src/api/admin.py b/src/api/admin.py index a57e682..6a70764 100644 --- a/src/api/admin.py +++ b/src/api/admin.py @@ -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: diff --git a/src/main.py b/src/main.py index 222d6aa..6bb62c0 100644 --- a/src/main.py +++ b/src/main.py @@ -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() diff --git a/src/services/file_cache.py b/src/services/file_cache.py index edeb100..ea56fa4 100644 --- a/src/services/file_cache.py +++ b/src/services/file_cache.py @@ -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 diff --git a/static/manage.html b/static/manage.html index 1f61ffc..88ec4e8 100644 --- a/static/manage.html +++ b/static/manage.html @@ -242,8 +242,8 @@