I'm working with a piece of code that looks similar to this (it's actually a lot more complicated but the code below captures the essence):
...
from functools import lru_cache
...
@lru_cache()
def toMemoize(flg, key, sig):
with open("/path/to/log" , "a") as f:
f.write(str(hash(flg)) + " " + str(hash(key)) + " " + str(hash(sig)) + "\n")
...
...
print(toMemoize.cache_info())
The output of the final print statement is:
CacheInfo(hits=0, misses=13, maxsize=128, currsize=13)
This informs methat the function was called 13 times but the cached vale was never used (hits=0). Inspecting /path/to/log:
2553775797797093876 364576801895165551 8302682858752407938
-4582445906785148513 364576801895165551 8302682858752407938
-4582445906785148513 364576801895165551 8302682858752407938
-4582445906785148513 364576801895165551 8302682858752407938
4000922257120027290 1417233507693056889 6473669797807631889
...
where each line contains the hash of arguments to toMemoize, it looks like this function was called multiple times with the same arguments. Why then is hits=0? Any clues, advice would be greatly appreciated.