Next: , Previous: , Up: Specific header arguments   [Contents][Index]

14.8.2.16 :cache

The :cache header argument controls the use of in-buffer caching of the results of evaluating code blocks. It can be used to avoid re-evaluating unchanged code blocks. Note that the :cache header argument will not attempt to cache results when the :session header argument is used, because the results of the code block execution may be stored in the session outside of the Org mode buffer. The :cache header argument can have one of two values: yes or no.

Code block caches notice if the value of a variable argument to the code block has changed. If this is the case, the cache is invalidated and the code block is re-run. In the following example, caller will not be re-run unless the results of random have changed since it was last run.

 #+NAME: random
 #+BEGIN_SRC R :cache yes
 runif(1)
 #+END_SRC

 #+RESULTS[a2a72cd647ad44515fab62e144796432793d68e1]: random
 0.4659510825295

 #+NAME: caller
 #+BEGIN_SRC emacs-lisp :var x=random :cache yes
 x
 #+END_SRC

 #+RESULTS[bec9c8724e397d5df3b696502df3ed7892fc4f5f]: caller
 0.254227238707244