This section contains step-by-step guides for common workflows.
from datetime import timedelta
from py_cashier import cache
from py_cashier.storages.ttl_map import TTLMapStorage
@cache(storage=TTLMapStorage.create_with(max_size=1000, ttl=timedelta(minutes=10)))
def get_item(key: str) -> str:
return f"value:{key}"from typing import Annotated
from py_cashier import cache, CacheWith
from py_cashier.storages.ttl_map import TTLMapStorage
# Cache only by `x`, ignore `y` in the cache key
@cache(storage=TTLMapStorage.create_with())
def f_cached(x: Annotated[int, CacheWith()], y: int) -> int:
return x + y