jsf - Basic cache question -


Say I have a JSF backing bean, request scope, which has a list as a member. In the backing bean, I have a method that is connected to a button on the page.

When the button is pressed first, the method uses EJB to populate the list. On the post-button press, I do not want to call DB.

Then, I added a check:

  if (list == null || List.size () == 0) // Populate the list  

Otherwise, the list will be populated already, so no DB call is necessary. Is it satisfying for caching mechanisms?

Because Bean's request is scope, its members will only be present for the lifetime of a single request, The page to be requested will be received.

Whatever you can do, it may contain cached data in a different area (such as sessions or applications).

  & lt; Managed-Bean & gt; & Lt; Managed-name names & gt; ExpensiveBean & lt; / Managed-name names & gt; & Lt; Successful bean category & gt; Life.ExpensiveBean & lt; / Successful bean category & gt; & Lt; Realm of managed-beams & gt; Session & lt; / Managed-beans scope & gt; & Lt; / Successful bean> & Lt; Successful Bean & gt; & Lt; Managed-name names & gt; RequestBean & lt; / Managed-name names & gt; & Lt; Successful bean category & gt; Lifetime.RequestBean & lt; / Successful bean category & gt; & Lt; Realm of managed-beams & gt; Request & lt; / Managed-beans scope & gt; & Lt; Managed-asset & gt; & Lt; Asset-name & gt; CachedAsset & lt; / Property-name & gt; & Lt; Property Category & gt; Life.ExpensiveBean & lt; / Property Category & gt; & Lt; Price & gt; # {ExpensiveBean} & lt; / Pricing & gt; & Lt; / Managed-properties & gt; & Lt; / Successful bean>  

sample code:

  public class request bin {personal legalbine cached asset; Public expensive bean getCachedAsset () {cachedAsset return; } Public Zero setCachedAsset (Expensive Bean Cached Asset) {this.cachedAsset = cachedAsset; }}  

In this way, you can easily reference the data from a request scope bean while keeping the request-level artwork apart.

Some frameworks add support for the scope of the page, which keeps data off the lifetime of viewing. This may be another option depending on your needs.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -