9
$\begingroup$

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];
$\endgroup$
3
  • $\begingroup$ Yay, thanks for the upvote, 1000 rep :D $\endgroup$ Commented Apr 23, 2013 at 11:48
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Apr 23, 2013 at 11:52
  • $\begingroup$ @OleksandrR. Thank you, I fixed things by just considering the graph examples and removing my hypothesis that all Graphics get cached. $\endgroup$ Commented Apr 23, 2013 at 12:17

1 Answer 1

7
$\begingroup$

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

SetSystemOptions["GraphOptions" -> "CacheResults" -> False]
$\endgroup$
1
  • $\begingroup$ Nice, this works. It is nice to see they added this option in version 10. Thank you for going back to my old question. $\endgroup$ Commented Oct 4, 2014 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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