Spaces:
Running
Running
Download backend/common/cache_manager.py from soiz1/Whisper-WebUI: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/soiz1/Whisper-WebUI/resolve/main/backend/common/cache_manager.py
- Command line
-
hf download hf://spaces/soiz1/Whisper-WebUI/backend/common/cache_manager.py
-
curl -L -o cache_manager.py https://huggingface.co/spaces/soiz1/Whisper-WebUI/resolve/main/backend/common/cache_manager.py
718 Bytes
| import time | |
| import os | |
| from typing import Optional | |
| from modules.utils.paths import BACKEND_CACHE_DIR | |
| def cleanup_old_files(cache_dir: str = BACKEND_CACHE_DIR, ttl: int = 60): | |
| now = time.time() | |
| place_holder_name = "cached_files_are_generated_here" | |
| for root, dirs, files in os.walk(cache_dir): | |
| for filename in files: | |
| if filename == place_holder_name: | |
| continue | |
| filepath = os.path.join(root, filename) | |
| if now - os.path.getmtime(filepath) > ttl: | |
| try: | |
| os.remove(filepath) | |
| except Exception as e: | |
| print(f"Error removing {filepath}") | |
| raise | |