`functools.lru_cache` caches the results of expensive function calls. It improves performance by avoiding redundant calculations.
Example:
from functools import lru_cache
@lru_cache(maxsize=3)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
print(fib(10))
Leave a Reply