Skip to content

CacheSettings

🛈 DocStrings

Where and how long responses are cached (enabled=False: not at all).

Source code in src/anyenv/download/session.py
@dataclass(frozen=True, slots=True)
class CacheSettings:
    """Where and how long responses are cached (``enabled=False``: not at all)."""

    enabled: bool
    directory: pathlib.Path
    ttl: int
    backend: CacheType = "file"

    @classmethod
    def create(
        cls,
        cache: bool | None = False,
        cache_dir: StrPath | None = None,
        cache_ttl: int | str | None = None,
        cache_backend: CacheType = "file",
    ) -> CacheSettings:
        """Resolve the defaults (user cache dir, one hour) and parse a TTL like "1d"."""
        from appdirs import user_cache_dir  # type: ignore[import-untyped]

        return cls(
            enabled=bool(cache),
            directory=pathlib.Path(cache_dir or user_cache_dir("anyenv", False)),
            ttl=parse_ttl(cache_ttl),
            backend=cache_backend,
        )

create classmethod

create(
    cache: bool | None = False,
    cache_dir: StrPath | None = None,
    cache_ttl: int | str | None = None,
    cache_backend: CacheType = "file",
) -> CacheSettings

Resolve the defaults (user cache dir, one hour) and parse a TTL like "1d".

Source code in src/anyenv/download/session.py
@classmethod
def create(
    cls,
    cache: bool | None = False,
    cache_dir: StrPath | None = None,
    cache_ttl: int | str | None = None,
    cache_backend: CacheType = "file",
) -> CacheSettings:
    """Resolve the defaults (user cache dir, one hour) and parse a TTL like "1d"."""
    from appdirs import user_cache_dir  # type: ignore[import-untyped]

    return cls(
        enabled=bool(cache),
        directory=pathlib.Path(cache_dir or user_cache_dir("anyenv", False)),
        ttl=parse_ttl(cache_ttl),
        backend=cache_backend,
    )

:fa-brands-github: Show source on GitHub