Skip to content

Dummy

Dummy backend that always succeeds but never stores anything. Any values get forgotten immediately, and operations behave as if the cache always is empty.

Supported URLs

  • dummy://

cachetory.backends.sync.DummyBackend

Dummy backend that stores nothing.

Source code in cachetory/backends/sync/dummy.py
class DummyBackend(SyncBackend[WireT], Generic[WireT]):
    """Dummy backend that stores nothing."""

    @classmethod
    def from_url(cls, url: str) -> DummyBackend[WireT]:
        return DummyBackend()

    def get(self, key: str) -> WireT:  # pragma: no cover
        raise KeyError(key)

    def get_many(self, *keys: str) -> Iterable[tuple[str, WireT]]:  # pragma: no cover
        return []

    def expire_in(self, key: str, time_to_live: timedelta | None = None) -> None:  # pragma: no cover
        return None

    def expire_at(self, key: str, deadline: datetime | None) -> None:  # pragma: no cover
        return None

    def set(  # noqa: A003
        self,
        key: str,
        value: WireT,
        *,
        time_to_live: timedelta | None = None,
        if_not_exists: bool = False,
    ) -> bool:  # pragma: no cover
        return True

    def set_many(self, items: Iterable[tuple[str, WireT]]) -> None:  # pragma: no cover
        return None

    def delete(self, key: str) -> bool:  # pragma: no cover
        return False  # has never been there

    def clear(self) -> None:  # pragma: no cover
        return None  # already perfectly clean

cachetory.backends.async_.DummyBackend

Dummy backend that stores nothing.

Source code in cachetory/backends/async_/dummy.py
class DummyBackend(AsyncBackend[WireT], Generic[WireT]):
    """Dummy backend that stores nothing."""

    @classmethod
    def from_url(cls, url: str) -> DummyBackend[WireT]:
        return DummyBackend()

    async def get(self, key: str) -> WireT:  # pragma: no cover
        raise KeyError(key)

    async def get_many(self, *keys: str) -> AsyncIterable[tuple[str, WireT]]:
        for _ in ():  # pragma: no cover
            yield ()  # type: ignore

    async def expire_in(self, key: str, time_to_live: timedelta | None = None) -> None:  # pragma: no cover
        return None

    async def expire_at(self, key: str, deadline: datetime | None) -> None:  # pragma: no cover
        return None

    async def set(  # noqa: A003
        self,
        key: str,
        value: WireT,
        *,
        time_to_live: timedelta | None = None,
        if_not_exists: bool = False,
    ) -> bool:  # pragma: no cover
        return True

    async def set_many(self, items: Iterable[tuple[str, WireT]]) -> None:  # pragma: no cover
        return None

    async def delete(self, key: str) -> bool:  # pragma: no cover
        return False  # has never been there

    async def clear(self) -> None:  # pragma: no cover
        return None  # already perfectly clean