How can I make @functools.lru_cache
decorator ignore some of the function arguments with regard to caching key?
For example, I have a function that looks like this:
def find_object(db_handle, query):
# (omitted code)
return result
If I apply lru_cache
decorator just like that, db_handle
will be included in the cache key. As a result, if I try to call the function with the same query
, but different db_handle
, it will be executed again, which I'd like to avoid. I want lru_cache
to consider query
argument only.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…