Joblib's cache functionality in joblib.Memory does not preserve type annotations of the underlying function.
That poses obstacles for pydantic validation and for modern type checkers and autocompletion in IDEs.
This package simply defines an incomplete adapter for the cache functionality.
uv add joblib-typed-cacheThe package offers a drop-in replacement for joblib.Memory.cache.
from typed_joblib_cache import Memory
cache = Memory(location="~/.cache", verbose=0)
@cache(ignore=["db_connection"])
def get_user(user_id: str, db_connection: str) -> dict[str, str]:
# Simulate data retrieval
return {"user_id": user_id, "email": "john@example.com", "transaction_id": 42}In this example, the function get_user will retain helpful tooltips in IDE and can also be used in conjunction with pydantic type validation.
import pydantic
get_user_validated = validate_call(get_user)