Moved hishel cache directory into spoolmans data directory

This is to prevent permission issues
This commit is contained in:
Donkie
2024-05-21 11:25:08 +02:00
parent 0ab6e92d65
commit 620febc3ab
3 changed files with 12 additions and 10 deletions

View File

@@ -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.

View File

@@ -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()

View File

@@ -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: