Spaces:
Runtime error
Runtime error
| # Copyright 2025 Google LLC | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| """Cache manager for Sushruta Patient 360 using diskcache.""" | |
| import logging | |
| import shutil | |
| from pathlib import Path | |
| from diskcache import Cache | |
| from config import CACHE_DIR | |
| logger = logging.getLogger(__name__) | |
| # Ensure CACHE_DIR exists | |
| try: | |
| CACHE_DIR.mkdir(parents=True, exist_ok=True) | |
| except Exception as e: | |
| logger.warning("Could not create CACHE_DIR %s: %s. Using local ./cache instead.", CACHE_DIR, e) | |
| CACHE_DIR = Path(__file__).resolve().parent / "cache" | |
| CACHE_DIR.mkdir(parents=True, exist_ok=True) | |
| # Define Cache instances | |
| intake_cache = Cache(str(CACHE_DIR / "intake")) | |
| radiology_cache = Cache(str(CACHE_DIR / "radiology")) | |
| logger.info("Initialized diskcache at: %s", CACHE_DIR) | |
| def create_cache_zip(archive_path_prefix: str) -> str: | |
| """Create a zip archive of the CACHE_DIR and return the path to the zip file. | |
| Saves it as `archive_path_prefix.zip`. | |
| """ | |
| zip_path = shutil.make_archive(archive_path_prefix, "zip", str(CACHE_DIR)) | |
| logger.info("Created cache archive zip at: %s", zip_path) | |
| return zip_path | |