I have several variables in my DynamicModule and some parts of my computation depend only on subset of them. I am trying to use Refresh to "cache" values but can't make it work.
Example of the problem:
verySlowFunction[x_] := Module[{}, Print["SLOW"]; x * x];
DynamicModule[
{a = 1, b = 1},
Dynamic[
Module[
{ x = Refresh[verySlowFunction[a], TrackedSymbols :> {a}] },
Column[{
Slider[Dynamic[a]],
Slider[Dynamic[b]],
{a, b , x + x + b}
}]]]]
I expect "SLOW" to be printed only when I drag "a" slider, but it is printed when I'm dragging "b" slider as well.
I know that Dynamic clones whole expression tree on its evaluation, that's why x is always different, but this one doesn't work as well:
Module[
{x},
DynamicModule[
{a = 1, b = 1},
Dynamic[
x = Refresh[verySlowFunction[a], TrackedSymbols :> {a}] ;
Column[{
Slider[Dynamic[a]],
Slider[Dynamic[b]],
{a, b , x + x + b}
}]]]]