Skip to content

Shortcuts

Sometimes, cache construction may become too wordy for a simple task. Consider this:

from cachetory.backends.sync import DummyBackend
from cachetory.caches.sync import Cache
from cachetory.serializers import NoopSerializer

dummy_cache: Cache[int, int] = Cache(
    serializer=NoopSerializer(),
    backend=DummyBackend(),
)

This subpackage provides shortcuts for a few common cases:

Synchronous

dummy_cache

dummy_cache() -> Cache[ValueT, ValueT]

Instantiate and return a dummy cache without a serializer.

Source code in cachetory/shortcuts/sync.py
def dummy_cache() -> Cache[ValueT, ValueT]:  # pragma: no cover
    """Instantiate and return a dummy cache without a serializer."""
    return Cache[ValueT, ValueT](serializer=NoopSerializer(), backend=DummyBackend())

memory_cache

memory_cache() -> Cache[ValueT, ValueT]

Instantiate and return a local memory cache without a serializer.

Source code in cachetory/shortcuts/sync.py
def memory_cache() -> Cache[ValueT, ValueT]:  # pragma: no cover
    """Instantiate and return a local memory cache without a serializer."""
    return Cache[ValueT, ValueT](serializer=NoopSerializer(), backend=MemoryBackend())

Asynchronous

dummy_cache

dummy_cache() -> Cache[ValueT, ValueT]

Instantiate and return a dummy cache without a serializer.

Source code in cachetory/shortcuts/async_.py
def dummy_cache() -> Cache[ValueT, ValueT]:  # pragma: no cover
    """Instantiate and return a dummy cache without a serializer."""
    return Cache[ValueT, ValueT](serializer=NoopSerializer(), backend=DummyBackend())

memory_cache

memory_cache() -> Cache[ValueT, ValueT]

Instantiate and return a local memory cache without a serializer.

Source code in cachetory/shortcuts/async_.py
def memory_cache() -> Cache[ValueT, ValueT]:  # pragma: no cover
    """Instantiate and return a local memory cache without a serializer."""
    return Cache[ValueT, ValueT](serializer=NoopSerializer(), backend=MemoryBackend())