4

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?

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
kyrenia
  • 5,431
  • 9
  • 63
  • 93

1 Answers1

7

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)
Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253