Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset the cache in lru_cache [duplicate]

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?

like image 889
kyrenia Avatar asked Oct 20 '25 15:10

kyrenia


1 Answers

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)
like image 112
Dimitris Fasarakis Hilliard Avatar answered Oct 22 '25 04:10

Dimitris Fasarakis Hilliard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!