Skip to content

hyperion.adapters.cache.filesystem

hyperion.adapters.cache.filesystem

Filesystem-backed :class:Cache adapter (lite -- stdlib only).

snappy compression is delegated to the abstract base; it degrades gracefully when python-snappy is not installed.

LocalFileCache

LocalFileCache(prefix, hash_keys=True, default_ttl=DEFAULT_TTL_SECONDS, root_path=None, max_size=DEFAULT_LOCAL_FILE_CACHE_MAX_SIZE, use_compression=True)

Bases: Cache

A local file cache for our shenanigans.

Source code in hyperion/adapters/cache/filesystem.py
def __init__(
    self,
    prefix: str,
    hash_keys: bool = True,
    default_ttl: int = DEFAULT_TTL_SECONDS,
    root_path: Path | None = None,
    max_size: int | None = DEFAULT_LOCAL_FILE_CACHE_MAX_SIZE,
    use_compression: bool = True,
) -> None:
    super().__init__(prefix, hash_keys, default_ttl)
    self.root_path = root_path or (Path(tempfile.gettempdir()) / DEFAULT_LOCAL_FILE_CACHE_DIRNAME)
    if self.root_path.exists() and not self.root_path.is_dir():
        raise ValueError(f"Given local cache path ({self.root_path.as_posix()}) is not a directory.")
    self.use_compression = use_compression
    self.max_size = max_size
    self._assert_root_path()
    logger.info(f"Initialized LocalFileCache in {self.root_path.as_posix()}.", root_path=self.root_path.as_posix())
    if not hash_keys:
        logger.warning("When using filesystem cache, it is recommended to hash keys.")