Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 746 Bytes

File metadata and controls

28 lines (21 loc) · 746 Bytes

Tutorials

This section contains step-by-step guides for common workflows.

1. Configure TTL and max size

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}"

2. Cache only specific arguments (type-annotated)

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