[Nitro] How iterate efficiently through collection of 'things'?

Aleksi Niemela Aleksi.Niemela at cs.helsinki.fi
Sun Sep 4 15:24:43 EDT 2005

Imagine the program gets some parameters out from user with first page, 
calculates a while and wants to show very big result set on multiple 
pages. To get this concrete, imagine user says "I want to see all known 
pieces of DNA which (approximately) match with this one I give you", 
then the program goes out to make a query and gets back with 900 best 
hits. Then it should show one piece of DNA, the match highlighted, per 
page and let the user go through Pager kind of list to get back and 
forth within proximity of current hit, and have quick access to the ends 
of the hit list.

Now, we don't want to make the query for the DNA database server each 
time user clicks "next hit". Some kind of temporary storage is needed 
for the results. Where one should store the results in Nitro development?

In Wee, I'd have an instance variable at the Controller object pointing 
to the result set and another indicating index. In Nitro the controller 
object lives only during one page generation. Nitro::Flash is can be 
used on temporary storage either, it's too short living. OTOH, Nitro 
discourages using session object and using state that's not persistent 
at all, like said at Nitro::Session rdocs

   State is a neccessary evil but session variables should be avoided as 
much as
   possible. Session <cid:part1.07010203.05010108 at cs.helsinki.fi> state 
is typically distributed to many servers so avoid storing
   complete objects in session variables, only store oids and small 

I suppose one could misuse Caching, namely MemoryStore. What's the idiom 
here? How and where the MemoryStore should be instantiated and cleaned 
up? What's the preferable way to use it?

I guess there's currently no example for this, so it would be great if 
someone (George, perhaps) could cook up a simple example providing 
answer this quite common need.

   - Aleksi

More information about the Nitro-general mailing list