Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


--displays--> a graph with the same pretty colors (and does not print messages)

even though

g // FullForm // InputForm


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


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


but setting all the rules of the form

"Cache"-> True


"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];
  "CacheOptions" -> "ParametricFunction" -> "Cache" -> False];
SetSystemOptions["CacheOptions" -> "Quantity" -> "Cache" -> False];
SetSystemOptions["CacheOptions" -> "Symbolic" -> "Cache" -> False];
share|improve this question
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
up vote 6 down vote accepted

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

SetSystemOptions["GraphOptions" -> "CacheResults" -> False]
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.