diff --git a/spoolman/env.py b/spoolman/env.py index 40e2970..b64f582 100644 --- a/spoolman/env.py +++ b/spoolman/env.py @@ -264,6 +264,11 @@ def get_backups_dir() -> Path: return backups_dir +def get_cache_dir() -> Path: + """Get the cache directory.""" + return get_data_dir() / "cache" + + def get_version() -> str: """Get the version of the package. diff --git a/spoolman/externaldb.py b/spoolman/externaldb.py index 6e382b3..96a767b 100644 --- a/spoolman/externaldb.py +++ b/spoolman/externaldb.py @@ -12,6 +12,7 @@ from pydantic import BaseModel, Field from scheduler.asyncio.scheduler import Scheduler from spoolman import filecache +from spoolman.env import get_cache_dir logger = logging.getLogger(__name__) @@ -21,12 +22,13 @@ DEFAULT_SYNC_INTERVAL = 3600 controller = hishel.Controller(allow_stale=True) try: - cache_storage = hishel.AsyncFileStorage() + cache_path = get_cache_dir() / "hishel" + cache_storage = hishel.AsyncFileStorage(base_path=cache_path) except PermissionError: logger.warning( "Failed to setup disk-based cache due to permission error. Ensure the path %s is writable. " "Using in-memory cache instead as fallback.", - str(Path(".cache/hishel").resolve()), + str(cache_path.resolve()), ) cache_storage = hishel.AsyncInMemoryStorage() diff --git a/spoolman/filecache.py b/spoolman/filecache.py index 5318bfa..3221d85 100644 --- a/spoolman/filecache.py +++ b/spoolman/filecache.py @@ -2,17 +2,12 @@ from pathlib import Path -from spoolman.env import get_data_dir - - -def _get_cache_dir() -> Path: - """Get the cache directory.""" - return get_data_dir() / "cache" +from spoolman.env import get_cache_dir def get_file(name: str) -> Path: - """Get the path to a file.""" - return _get_cache_dir() / name + """Get the path to a file in the cache dir.""" + return get_cache_dir() / name def update_file(name: str, data: bytes) -> None: