jsf - Which is better? - Querying database every time or keeping objects in session -


i have 2 pieces of code same thing. fill datatable in 2 different ways. here they:

<h:datatable  binding="#{currentuser.items}"   style=" width:505px;"   id="usertable" value="#{currentuser.items}" var="user"  >     <h:column>      </h:column>     <h:column>         <f:facet name="header">account number</f:facet>              #{user.name}     </h:column>     <h:column>         <f:facet name="header">currency</f:facet>             #{user.surname}     </h:column>                 </h:datatable> 

where items array contains user's items , currentuser session scoped class object of type user. in first code, when user logins, items database, , add them session use later, fill table in way. second version:

<h:datatable  binding="#{user.items}"   style=" width:505px;"   id="usertable" value="#{user.items}" var="user"  >     <h:column>      </h:column>     <h:column>         <f:facet name="header">account number</f:facet>              #{user.name}     </h:column>     <h:column>         <f:facet name="header">currency</f:facet>             #{user.surname}     </h:column>                 </h:datatable> 

in second example, not keep items list when user logins system, whenever table filled, database query , fill table items of user.

so question is, way better? see in first case may harmful use lot of session objects in second case everytime need items info database search. can 1 way better other in terms of space, time etc?

caching data in session scoped object runs risk of providing stale data - if process modifies database's contents session scoped object won't reflect these changes. doesn't sound mutable data, though, in case isn't problem.

other that, caching data in session scoped object may better in terms of time since data kept in main memory, , going database each time may better in terms of space since you're not keeping data in memory. "may" qualifiers there because database may caching data you.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -