How can you change the behavior of the decorator lru_cache
from functools
so that the decorated function has a flag that indicates whether to cache this call or not.
for example
@new_lru_cache
def f(args, kwargs):
...body function...
f(1) # not saved
f(2, cache=True) # saved
If you are gonna write a whole function for it, why not copy-paste the original source and implement your logic there?
This way you have even more control over the function, and you can see everything easily, and you can play around with the inners of the functools this way.