Dec-03-2020, 11:06 PM
functools.cache is not going to know that expensive_function(6, 4) is the same as expensive_function(4, 6). But if this is an expensive function the order of the arguments is probably important.
Care must be taken if your cached function returns a mutable result. Just last week somebody was using functools to speed up their code and it led to unexpected results because a cached list was returned instead of generating a new list each time.
Care must be taken if your cached function returns a mutable result. Just last week somebody was using functools to speed up their code and it led to unexpected results because a cached list was returned instead of generating a new list each time.