very cool idea! i was also very interested in this problem during grad school ... prototyped an approach by hacking CPython, but the code (python 2.6? from 2010 era) has long bitrotted:
https://pg.ucsd.edu/publications/IncPy-memoization-in-Python...
https://pg.ucsd.edu/publications/IncPy-memoization-in-Python...