kyrenia kyrenia - 1 month ago 17
Python Question

Reset the cache in lru_cache

Is there any way of over-riding the

lru_cache
in python?

Specifically if I have a function such as:

import functools

@functools.lru_cache(maxsize=None)
def function_of_interest(variables):

...
return(processed_values)


Is is possible to reset the cache, and hence run-run the function?

Answer

Is is possible to reset the cache, and hence re-run the function?

If my understanding is correct, you can just use cache_clear on the decorated function. If you've filled the cache by running it, this clears all indicators for you, that is:

function_of_interest.cache_clear()

Should result in a cache_info of:

CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)
Comments