Plenty of caches are built that have this property. Streamlit for example offers two different caching helpers, one is faster but only safe if you don't mutate the return value and one is slower but safer as it makes a copy. Diskcache, my go-to, appears to be safe with regards to this too.
Regardless of cache implementation, if the notebook input cells are run in a different sequence like 0,1,2,2,2,3 the output with caching there is not necessarily same as without caching and not necessarily the same as 0,1,2,2,3 ; caching alone does not achieve functional idempotency, in fact that's many more partners that can diverge when the interest is parametric reproducibility (and notebooks are already a strange abstraction for computation graphs complex enough to justify e.g. dask.cache.Cache() for, and there are reasons to not always enable dask.cache.Cache() globally (if the argument were whether auto-caching is safe enough to be the default behavior in notebooks))