7 Replies Latest reply on Nov 3, 2008 12:35 AM by Jack Daniels

    Refreshing a portlet's cache

    Jon Whitmore Newbie

      Hello

      I'm working with Jboss AS 4.0.3sp1 and JBoss portal 2.2. I have a portlet that displays statistical information about our system on the main page of our website. This information is updated in the database automatically each night. My portlet currently caches the statistical data to ensure quick page loads, but I need a way to tell it to drop it's cache.

      One solution is to use a timestamp and refresh my data when it's a day old. This will lead to one slow page load for some unlucky user. I want to avoid this.

      Another solution is to use the Scheduler http://jboss.org/index.html?module=bb&op=viewtopic&t=96668 but I'm not having much luck. I'm reading about MBeans and Classloaders now, but I'm running out of time.

      Is there another, easier why to do this? Are there any better examples of how to use the scheduler? (I need to understand why JBoss can't find a classloader for my Schedulable bean.)

      Thanks

      nollie


        • 1. Re: Refreshing a portlet's cache
          Antoine Herzog Master

          Hello,

          I am looking for quite the same.
          the main thing is to drop the cache.
          did you find a way to drop the cache, for one portlet independently ?
          how this can be done ?

          thank you,

          • 2. Re: Refreshing a portlet's cache
            Jon Whitmore Newbie

            Unfortunately, no I didn't find a good way to do this. At one point I had my scheduler bean running but I hadn't figured out how to be sure that it was using the same classloader as my portlet.

            Since my cache refresh was under 10 seconds we decided to let one user per day take the 'hit' and table the issue. In the future when we are using EJBs I'll revisit this.

            Here is a very simple timer example:

            CacheDumpScheduler.java:

            package com.foo;
            
            import java.util.Date;
            
            import org.jboss.varia.scheduler.Schedulable;
            
            public class CacheDumpScheduler implements Schedulable {
            
             public void perform(Date now, long remainingRepetitions) {
             MyPortlet.resetCache();
            
             }
            
            
            }

            META-INF/jboss-service.xml:
            <?xml version="1.0" encoding="UTF-8"?>
            <server>
             <mbean code="org.jboss.varia.scheduler.Scheduler" name="com.foo:service=CacheDumpScheduler">
             <attribute name="StartAtStartup">true</attribute>
             <attribute name="SchedulableClass">
             com.foo.CacheDumpScheduler
             </attribute>
             <attribute name="SchedulableArguments">
             </attribute>
             <attribute name="SchedulableArgumentTypes">
             </attribute>
             <attribute name="InitialStartDate">NOW</attribute>
             <attribute name="SchedulePeriod">6000</attribute>
             <attribute name="InitialRepetitions">-1</attribute>
             <depends>jboss.web:service=WebServer</depends>
             </mbean>
            
            </server>


            Hope that helps


            Jon


            • 3. Re: Refreshing a portlet's cache
              Antoine Herzog Master

              Hello,

              Thanks for the answer and the scheduller... but what I first need to do is to reset the cache of one portlet.

              what is in this method ?
              MyPortlet.resetCache();

              did I missed something obvious about the portlet cache (and JSR-168)?
              (I mean the UI and the html fragment cached between two requests).

              how can you say : reset the cache now for this portlet ?
              and force to go throught the doView method, even if the cache timeout is not over.

              It is not supposed to be done in the JSR-168 and I am looking for a "special JBoss portal implementation of cache" way to do it.

              Thanks again,
              Antoine

              • 4. Re: Refreshing a portlet's cache
                Jon Whitmore Newbie

                What are you caching?

                My portlet was caching some statistics from the database. These stats only change late at night, so there was no reason for me to perform the same query all day long. The idea behind my timer was to tell my portlet to access the DB again and save the new data.


                if you are talking about jboss caching your portlet or HTML fragment, my solution is probably not what you want. In my experience you can change the HTML or JSP fragments while the server is running and it will pick up the changes. However, the server will not pick up changes to the class files or properties files of your portlet. That requires a restart (or maybe just touching application.xml).



                • 5. Re: Refreshing a portlet's cache
                  Viet Master

                  You want to invalide the portlet cache per user and per window ?

                  • 6. Re: Refreshing a portlet's cache
                    Antoine Herzog Master

                    yes... per user and per window

                    to be able to refresh a portlet when some IPC messages tell him that "things have changed".
                    as an example : for navigation and have a menu that follow the change in the rest of the portal.

                    thanks

                    • 7. Re: Refreshing a portlet's cache
                      Jack Daniels Newbie

                      Was there a resolution to this problem???

                      Thanks.