How many times does this program print compute?

from lru_cache function caching
Python 3.14 beginner 2 min

How many times does this program print compute?

Python
from functools import lru_cache

@lru_cache(maxsize=2)
def read(key):
    print("compute")
    return key

for key in ["A", "B", "A", "C", "B"]:
    read(key)
Open in playground
Report an error