# Caching of Graph Graphics

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];

-
Yay, thanks for the upvote, 1000 rep :D –  Jacob Akkerboom Apr 23 '13 at 11:48
Sorry, that was mine, but had to unupvote because I can't reproduce your observations. Since Graphics isn't HoldAll, the color will be determined when gr is set and does not change thereafter whether the cache is cleared or not. Using SetDelayed to define gr (or adding Unevaluated) similarly produces the expected result. –  Oleksandr R. Apr 23 '13 at 11:52
@OleksandrR. Thank you, I fixed things by just considering the graph examples and removing my hypothesis that all Graphics get cached. –  Jacob Akkerboom Apr 23 '13 at 12:17

## 1 Answer

You can turn off caching in graphs by setting the system options:

SetSystemOptions["GraphOptions" -> "CacheResults" -> False]

-
Nice, this works. It is nice to see they added this option in version 10. Thank you for going back to my old question. –  Jacob Akkerboom Oct 4 '14 at 16:31