emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* babel: is it possible to cache #+call executed blocks
@ 2012-06-28 14:34 Jonas Hörsch
  2012-08-03 16:04 ` Arne Köhn
  0 siblings, 1 reply; 3+ messages in thread
From: Jonas Hörsch @ 2012-06-28 14:34 UTC (permalink / raw)
  To: emacs-orgmode

Hello everyone,

i'm looking for a possibilty to call lengthy codeblocks a few times with
different parameters, but would like the results to be cached.

hopefully wiw becomes clear enough with a minimal example.

the code block speak, if directly evaluated, produces the correct result
hallo on the first run. all subsequent runs just return immediately,
until the code block is changed.

if one evaluates the #+call line, as expected the right result is
returned and the hash necessary for caching is added to #+RESULTS.
but subsequent evaluations always seem to evaluate the code block again,
i.e. one has to wait the 5 seconds.

is there a way to avoid this?

thanks,
jonas

#+begin_src org

* Test
#+name: speak
#+begin_src sh :var say="hallo" :results output :cache yes
echo $say
sleep 5
#+end_src

#+RESULTS[4370bde991d63488bcb6d297718919fcf2b4fa1f]: speak
: hallo

#+call: speak('welt') :cache yes

#+RESULTS[c393aea840734e972880a4a38512765d345e7125]: speak('welt'):cache yes
: welt

#+end_src

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: babel: is it possible to cache #+call executed blocks
  2012-06-28 14:34 babel: is it possible to cache #+call executed blocks Jonas Hörsch
@ 2012-08-03 16:04 ` Arne Köhn
  2012-08-03 19:30   ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Arne Köhn @ 2012-08-03 16:04 UTC (permalink / raw)
  To: emacs-orgmode

coroa@online.de (Jonas Hörsch) writes:

> i'm looking for a possibilty to call lengthy codeblocks a few times with
> different parameters, but would like the results to be cached.

It's probably a bit late, but I stumbled over the same problem. Here is
how I dealt with it (it's not that pretty).

Instead of

,----
|  #+call foofunc(bar=baz)
`----

I wrote a emacs-lisp block doing the same:

,----
| #+name: speak_world
| #+begin_src emacs-lisp :cache yes
|   (save-excursion
|     (goto-char (org-babel-find-named-block "speak"))
|     (org-babel-execute-src-block nil nil '((:var "say=world")))
|   )
| #+end_src
`----

In contrast to #+call, this results in a cached result for foo_bar that
can be accessed later on.

The disadvantages:
 - the cached result will never be invalidated (since foo_bar doesn't
   change)
 - somehow the variable bar will not be "baz" but "baz=", I changed my
   code block to strip the trailing "=".

If someone could point out where this "=" comes from: please tell me!


Arne

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: babel: is it possible to cache #+call executed blocks
  2012-08-03 16:04 ` Arne Köhn
@ 2012-08-03 19:30   ` Eric Schulte
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2012-08-03 19:30 UTC (permalink / raw)
  To: Arne Köhn; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

arne@arne-koehn.de (Arne Köhn) writes:

> coroa@online.de (Jonas Hörsch) writes:
>
>> i'm looking for a possibilty to call lengthy codeblocks a few times with
>> different parameters, but would like the results to be cached.
>

Use #+call lines with the :cache header argument set.  With a recent
version of Org-mode the following should work as expected.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: call-cache.org --]
[-- Type: text/x-org, Size: 486 bytes --]

#+Title: An Example of Using the Cache Header Argument with Call Lines

A long running code block.
#+name: foo
#+begin_src emacs-lisp :var bar="baz"
  (sit-for 5)
  (message "bar=%S" bar)
#+end_src

#+RESULTS: foo
: bar="baz"

This returns immediately thanks to the cached result.
#+call: foo("qux") :cache yes

#+RESULTS[49bbb37e59694c557889ca8fd4b06fe0d4fb6b25]: foo("qux"):cache yes
: bar="qux"

This does not return immediately, because the block must execute.
#+call: foo("quxxx")

[-- Attachment #3: Type: text/plain, Size: 46 bytes --]


-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-08-03 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-28 14:34 babel: is it possible to cache #+call executed blocks Jonas Hörsch
2012-08-03 16:04 ` Arne Köhn
2012-08-03 19:30   ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).