On Sat, Sep 26, 2009 at 2:54 PM, David Pollak
<feeder.of.the.be...@gmail.com> wrote:
>
>
> On Sat, Sep 26, 2009 at 6:40 AM, Kevin Wright
> <kev.lee.wri...@googlemail.com> wrote:
>>
>> If the information is created just once and then used across multiple
>> requests, it'll be a lazy val in a singleton
>
> A lazy val in a singleton will not work.
> Once it's calculated, it's calculated and cannot be changed for the life of
> the singleton.  If the singleton is global scope, you're really hosed.
> RequestVars are the Lift way of sharing information across snippets on a
> request-by-request basis.
> If you want lazy evaluation of the RequestVar:
> object Invoice extends RequestVar(S.param("invoice_id").flatMap(id =>
> Invoice.find(id))) // type inferred to Box[Invoice]
> If you want to share information across the scope of your session, use a
> SessionVar.
> SessionVar works exactly like RequestVar, but the lifespan of the SessionVar
> is your session.
>

The OP never actually stated "share between snippets across a session"
or "share between snippets across a request".  It was simply "share
between snippets"

Almost certainly SessionVar or RequestVar are what will be needed, but
what if the data is truly global in nature?  Something like the 2001
average world exchange rates vs USD, which requires a costly
webservice or database lookup to find.

The original request was vague, but global caching is definitely one
possible interpretation of what was wanted.

>>
>> If it's request-dependent then it'll be a singleton extending RequestVar
>>
>> Sadly, the OP didn't specify what was needed :(
>>
>>
>> On Sat, Sep 26, 2009 at 2:35 PM, Timothy Perrett
>> <timo...@getintheloop.eu> wrote:
>> >
>> > Take a look at RequestVar... If he were to just use a object singleton
>> > he might end up being not thread safe.
>> >
>> > Cheers
>> >
>> > Tim
>> >
>> > Sent from my iPhone
>> >
>> > On 26 Sep 2009, at 14:05, Kevin Wright <kev.lee.wri...@googlemail.com>
>> > wrote:
>> >
>> >>
>> >> You could always try putting your lazy val inside a singleton object
>> >>
>> >> On Sat, Sep 26, 2009 at 8:14 AM, ishiijp <yoshinori.is...@gmail.com>
>> >> wrote:
>> >>>
>> >>> Hi.
>> >>>
>> >>> If my lift application have some data that cost to create, and I want
>> >>> to share it among snippets, how to do in Lift?
>> >>>
>> >>> if such data are shared inside one snippet, I may use "lazy val".
>> >>> But I have no nice idea to share it among different snippts.
>> >>>
>> >>> Thanks much.
>> >>>
>> >>>>
>> >>>
>> >>
>> >> >
>> >>
>> >
>> > >
>> >
>>
>>
>
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Beginning Scala http://www.apress.com/book/view/1430219890
> Follow me: http://twitter.com/dpp
> Surf the harmonics
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to