In this answer, Simon Woods concludes that when you display an expression with head graph more than once, something is getting stored somewhere. I looked into it too and found out this only happens if you tie the expression with head graph to a symbol. Evaluating the symbol a second time will no longer print messages and results of random numbers are the same. Consider this example
g=Graph[{1 -> 2, 2 -> 3, 3 -> 1},
VertexShapeFunction -> ({Random[] // Hue, Disk[Print["VSF"]; #, 0.05]} &)]
--prints--> messages --displays-> a graph with pretty colors
g
--displays--> a graph with the same pretty colors (and does not print messages)
even though
g // FullForm // InputForm
returns
(*output*)
FullForm[Graph[{1, 2, 3}, {DirectedEdge[1, 2], DirectedEdge[2, 3],
DirectedEdge[3, 1]}, {VertexShapeFunction ->
{{Hue[Random[]], Disk[Print["VSF"]; #1, 0.05]} & }}]]
where we can see that the colors are supposed to be generated randomly by the option VertexShapeFunction
.
However, after evaluating
ClearSystemCache[];
evaluating g will (almost almost surely ;) ) yield a graph with a new colors.
this Q&A seems related.
My question is: How can we turn off such caching?
We can find systemoptions having to do with Cache by evaluating
SystemOptions["Cache*"]
but setting all the rules of the form
"Cache"-> True
to
"Cache" -> False
does not change the way the graphics behave.
They do however influence the value of
Timing[N[Pi, 1000000]][[1]]
The SystemOptions can be set by evaluating
SetSystemOptions["CacheOptions" -> "Developer" -> "Cache" -> False];
SetSystemOptions["CacheOptions" -> "Numeric" -> "Cache" -> False];
SetSystemOptions[
"CacheOptions" -> "ParametricFunction" -> "Cache" -> False];
SetSystemOptions["CacheOptions" -> "Quantity" -> "Cache" -> False];
SetSystemOptions["CacheOptions" -> "Symbolic" -> "Cache" -> False];
Graphics
isn'tHoldAll
, the color will be determined whengr
is set and does not change thereafter whether the cache is cleared or not. UsingSetDelayed
to definegr
(or addingUnevaluated
) similarly produces the expected result. $\endgroup$