0 Replies Latest reply on Oct 28, 2010 1:48 PM by petitefl3ur.petitefl3ur.gmail.com

    Caching results

    petitefl3ur.petitefl3ur.gmail.com

      Hello,


      I have read the how to : avoid method or getter to be called several times by caching result


      and i have a question about the In-method cache.


      In my application i'm displaying on the home page some news. That's classical, and these news are retreiving from database in a init method :




      @Name("home")
      public HomeAction {
      
         @In private NewsDao newDao;
         private List<News> someNews = null;
         
         public String init() {
              someNews = newsDao.findLastNews();
         }
      
         public List<News> getSomeNews() {return someNews;} 
      
      }



      And in the home.xhtml i cache the results


      <s:cache cacheProvider="#{jboss2Cache}" key="homeLastNews" region="/enov/cache/fragment/home">
         ... the display in a dataTable of my news with #{home.someNews} ...
      </s:cache
      



      So my question is : like the In-method cache, can i test with my cache provider  if for this region the key is still in cache and so not making the call to the DAO and the database.


      Something like this :


      @Name("home")
      public HomeAction {
      
         @In(value="jboss2Cache") JbossCache2Provider jboss2Cache;
      
         @In private NewsDao newDao;
         private List<News> someNews = null;
         
         public String init() {
              if (jboss2Cache.get("/enov/cache/fragment/home","homeLastNews") == null) {
                 someNews = newsDao.findLastNews();
              }
         }
      
         public List<News> getSomeNews() {return someNews;} 
      
      }




      I'm thinking about this because even with a lot of page fragments in cache, beans are still doing a lot of useless queries...which are in cache too by the way...


      What do you think about that? Is this really good for performance?

      Merci!