You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Jeremy Wilson <je...@esrgtech.com> on 2009/06/26 12:56:05 UTC

Re: Caching the result of an EL expression evaluation with in a lifecycle

------Original Message------
From: Sam Witty
To: dev@myfaces.apache.org
ReplyTo: MyFaces Development
Sent: Jun 25, 2009 9:36 PM
Subject: Caching the result of an EL expression evaluation with in a lifecycle


If you have the following code:

<h:h:outputText>#{someBean.user.firstName}></h:outputText>
<h:h:outputText>#{someBean.user.lastName}></h:outputText>
<h:h:outputText>#{someBean.user.age}"></h:outputText>

and if SomeBean.user() is a call to the db then every one of the above
expressions will cause a trip to the db. Of course to get around this one
simply has to cache the value of user from the db (the first time) and then
return the cached value instead of going to the db again. 

This is all well and good... however, I find myself writing a lot of this
type of caching code in various places. It would seem that a much elegant
solution would be to have the EL expression evaluator cache the result of an
expression within a life cycle avoiding the need for every JSF developer to
sprinkle caching code all over the place.

Then again there maybe something out there that does this already (magical
config param?) I just could not find anything.

Thanks
-Sam
-- 
View this message in context: http://www.nabble.com/Caching-the-result-of-an-EL-expression-evaluation-with-in-a-life-cycle-tp24213650p24213650.html
Sent from the My Faces - Dev mailing list archive at Nabble.com.



Jeremy Wilson
CTO
ESRG Technologies Group
Office 757-965-5963
Cell 814-241-4500

Re: Caching the result of an EL expression evaluation with in a lifecycle

Posted by Alan Hancock <su...@gmail.com>.
Use JPA to get the data. You'll need a service and an entity object.  
Then your backing bean can use the service layer to retrieve the  
entire object.

This approach handles caching for you and is much more scalable

-Alan via iPhone


On Jun 26, 2009, at 5:56 AM, "Jeremy Wilson"  
<je...@esrgtech.com> wrote:

>
> ------Original Message------
> From: Sam Witty
> To: dev@myfaces.apache.org
> ReplyTo: MyFaces Development
> Sent: Jun 25, 2009 9:36 PM
> Subject: Caching the result of an EL expression evaluation with in a  
> lifecycle
>
>
> If you have the following code:
>
> <h:h:outputText>#{someBean.user.firstName}></h:outputText>
> <h:h:outputText>#{someBean.user.lastName}></h:outputText>
> <h:h:outputText>#{someBean.user.age}"></h:outputText>
>
> and if SomeBean.user() is a call to the db then every one of the above
> expressions will cause a trip to the db. Of course to get around  
> this one
> simply has to cache the value of user from the db (the first time)  
> and then
> return the cached value instead of going to the db again.
>
> This is all well and good... however, I find myself writing a lot of  
> this
> type of caching code in various places. It would seem that a much  
> elegant
> solution would be to have the EL expression evaluator cache the  
> result of an
> expression within a life cycle avoiding the need for every JSF  
> developer to
> sprinkle caching code all over the place.
>
> Then again there maybe something out there that does this already  
> (magical
> config param?) I just could not find anything.
>
> Thanks
> -Sam
> -- 
> View this message in context: http://www.nabble.com/Caching-the-result-of-an-EL-expression-evaluation-with-in-a-life-cycle-tp24213650p24213650.html
> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>
>
>
> Jeremy Wilson
> CTO
> ESRG Technologies Group
> Office 757-965-5963
> Cell 814-241-4500