Nhảy đến nội dung chính

Caching / Memoization

Dùng để lưu kết quả tạm để tránh tính toán lại:

from functools import lru_cache

@lru_cache(maxsize=128)
def slow_function(x):
    print(f"Calculating {x}")
    return x * x