functools.cache on pure functions that are called repeatedly
A settings loader, a compiled regex, a lookup that hits disk. If the inputs are hashable and the output never changes, cache it in one line.
@functools.cache
def load_schema(name: str) -> dict: ...lru_cache(maxsize=…) when the input space is large. Neither is right for anything with side effects or for values that change while the process runs.
pythonperformance