Cache results between function calls in Optimization.jl

Ohh I see :sweat_smile: thank you for the tips! I think this is trickier than I thought. When using reinterpret with the memoization function from the original post I ran into issues similar to Issue with PDMP and Forwardiff - DifferentialEquation - #27 by vettert
I will have a closer look…