Best practice for deferred evaluation/batch processing of snippets

36 views
Skip to first unread message

Colin Dellow

unread,
Apr 11, 2012, 10:07:25 AM4/11/12
to Lift
I need to do an expensive operation (a DB request, a file system
check), potentially N times. I'd like to batch up the requests so I
only pay the network latency cost once. This works if only a single
massive snippet is reponsible for all the requests, but not so well if
multiple snippets contribute to the final document, all of which may
need to do the operation.

Is there a way to defer snippet evaluation until the last minute,
where a method has access to the entire output and can batch things
up?

The approach I'm currently thinking of is to emit something like
<makeLink id="baz"/>, hook into LiftRules.convertResponse and do a
transformation there, which feels a bit dirty.

David Pollak

unread,
Apr 11, 2012, 1:36:22 PM4/11/12
to lif...@googlegroups.com
You can run multiple snippets in parallel using Parallel Rendering:

If you are looking to do an expensive computation to share across multiple snippets, you can use RequestVars and have the computation be the default value of the RequestVar... that way the result is cached.

Hope this helps.


--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Colin Dellow

unread,
Apr 11, 2012, 3:17:52 PM4/11/12
to Lift
> You can run multiple snippets in parallel using Parallel Rendering:http://seventhings.liftweb.net/parallel
>
> If you are looking to do an expensive computation to share across multiple
> snippets, you can use RequestVars and have the computation be the default
> value of the RequestVar... that way the result is cached.

Ah, a lightbulb just went off for me. Thank you! Parallel snippets + a
RequestVar to cache previous lookups should get me there.
Reply all
Reply to author
Forward
0 new messages