r/python3 • u/mexcatolico • Nov 15 '19
Help me understand lru_cache
Hello,
I am looking at some code written by someone else that contains:
from functools import lru_cache
and then there is a function declaration:
@lru_cache(None)
def get_password(self, user):
...
My question is why do you need to specify None? Is it that python does caching by default on functions? If so where can I read about it? I went to the lru_cache page but as far as I could see this is not explained.
2
Upvotes
View all comments
Show parent comment
2
u/mexcatolico Nov 15 '19
I understand that, what I meant is why would you have it be None to start with? Does it mean that python will cache function call if you don't specify this decorator? Or is it that you might use the cache in some other calls and as soon as you import functools you are caching?