You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by Paul Spencer <pa...@mikon.com> on 2001/10/06 01:43:10 UTC

[PATCH] Local WebPagePortlets ignore cache-control and expire in HTTP header

The patch below, which I can commit, sets the expiration of the cached
object to match
the expiration of the portlet content.  This is implemented on the
WebPagePortlet using the expiration time in the HTTP response header,
not the <META HTTP-EQUIV..> tag. Objects that have not set an expiration
in the Cacheable interface, which is the pre-patch behavior, will
continue to expire using the turbine default behavior.

My testing has been successfully completed.  May I commit this patch?

Paul Spencer

Index: services/portletcache/Cacheable.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletcache/Cacheable.java,v
retrieving revision 1.3
diff -c -r1.3 Cacheable.java
*** services/portletcache/Cacheable.java	2001/06/04 17:30:37	1.3
--- services/portletcache/Cacheable.java	2001/10/05 23:22:35
***************
*** 103,107 ****
--- 103,120 ----
      */
      public void setHandle( String handle );
    
+     /**
+      * Return the expiration time in milliseconds.
+      @return Expiration time in milliseconds since epoch, or null if
the 
+      *         expiration was not set
+      */
+     public Long getExpirationMillis();
+ 
+     /**
+     * Set the expiration time in milliseconds.
+     @param setExpirationMillis Expiration in milliseconds since epoch
+     */
+     public void setExpirationMillis( long expirationMillis);
+ 
  
  }
Index: services/portletcache/JetspeedPortletCacheService.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletcache/JetspeedPortletCacheService.java,v
retrieving revision 1.4
diff -c -r1.4 JetspeedPortletCacheService.java
*** services/portletcache/JetspeedPortletCacheService.java	2001/03/07
06:48:50	1.4
--- services/portletcache/JetspeedPortletCacheService.java	2001/10/05
23:22:35
***************
*** 108,115 ****
          }
          
          if ( item.isCacheable() ) {
!             GlobalCache.addObject( handle, new CachedObject( item ) );
!         }
  
      }
      
--- 108,125 ----
          }
          
          if ( item.isCacheable() ) {
!             Long expirationMillis = item.getExpirationMillis();
!             if (expirationMillis != null) {
!               // Only cache objects that have not expired.
!               if (System.currentTimeMillis() <
expirationMillis.longValue()) {
!                 GlobalCache.addObject( handle, new CachedObject( item,
expirationMillis.longValue() - System.currentTimeMillis()) );
!               }
!             } else {
!               // Oject will be cached Turbine
"cachedobject.defaultage"
!               GlobalCache.addObject( handle, new CachedObject( item )
);
!             }
!       }
! 
  
      }
      
Index: portal/portlets/AbstractPortlet.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/AbstractPortlet.java,v
retrieving revision 1.45
diff -c -r1.45 AbstractPortlet.java
*** portal/portlets/AbstractPortlet.java	2001/09/10 22:41:00	1.45
--- portal/portlets/AbstractPortlet.java	2001/10/05 23:22:36
***************
*** 111,116 ****
--- 111,122 ----
      private String        handle          = "";
  
      /**
+     Expiration time of object in milliseconds since the standard base
time
+     known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
+     */
+     private Long          expirationMillis = null;
+ 
+     /**
      Holds instances of ConcreteElements (Portlet output/content) 
      based on its current CapabilityMap.
      */
***************
*** 201,206 ****
--- 207,227 ----
      */
      public final void setHandle( String handle ) {
          this.handle = handle;
+     }
+ 
+     /**
+     @see Cacheable#getExpirationMillis
+     */
+     public Long getExpirationMillis() {
+       return this.expirationMillis;
+     }
+     
+ 
+     /**
+     @see Cacheable#setExpirationMillis
+     */
+     public void setExpirationMillis( long expirationMillis) {
+       this.expirationMillis = new Long(expirationMillis);
      }
  
      /** Builds a new cache handle for this cacheable class with the
specified
Index: portal/portlets/WebPagePortlet.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/WebPagePortlet.java,v
retrieving revision 1.2
diff -c -r1.2 WebPagePortlet.java
*** portal/portlets/WebPagePortlet.java	2001/03/07 06:47:17	1.2
--- portal/portlets/WebPagePortlet.java	2001/10/05 23:22:37
***************
*** 128,139 ****
      
      /**
       * took this from FileServerPortlet as it was private 
      */
      private String getURL(String url) throws IOException {
  
          int CAPACITY = 1024;
  
!         InputStream is = new URL( url ).openStream();
          ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  
          //now process the InputStream...
--- 128,145 ----
      
      /**
       * took this from FileServerPortlet as it was private 
+      *
+      * FIXME: Currently only the expiration the HTTP Reponse header is
honored. 
+      *        Expiration information in <meta> tags are not honored 
      */
      private String getURL(String url) throws IOException {
  
          int CAPACITY = 1024;
+         URL            pageUrl = new URL(url);
+         URLConnection  pageConn = pageUrl.openConnection();
+         long           pageExpiration = pageConn.getExpiration();
  
!         InputStream is = pageUrl.openStream();
          ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  
          //now process the InputStream...
***************
*** 147,152 ****
--- 153,163 ----
  
          is.close();
  
+         // Only set the page expiration it the page has not expired
+         if (pageExpiration > System.currentTimeMillis()) {
+           Log.debug( "WebPagePortlet caching URL: " + url + "
Expiration: " + pageExpiration);
+           setExpirationMillis(pageExpiration);
+         }
  
          return buffer.toString();

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Re: [PATCH] Local WebPagePortlets ignore cache-control and expire in HTTP header

Posted by Santiago Gala <sg...@hisitech.com>.
Paul Spencer wrote:

>The patch below, which I can commit, sets the expiration of the cached
>object to match
>the expiration of the portlet content.  This is implemented on the
>WebPagePortlet using the expiration time in the HTTP response header,
>not the <META HTTP-EQUIV..> tag. Objects that have not set an expiration
>in the Cacheable interface, which is the pre-patch behavior, will
>continue to expire using the turbine default behavior.
>
>My testing has been successfully completed.  May I commit this patch?
>
It looks reasonable. While looking at this, I observed that there is no 
interface for cache control in the new Portlet API. I wonder if the IBM 
team has already any experience regarding caching of portlets.

We could consider that caching of Portlet instances should belong to the 
portlet container, but a standard interface for signalling cacheability 
life cycle would make easier life cycle control in different containers.

>
>
>Paul Spencer
>
>Index: services/portletcache/Cacheable.java
>===================================================================
>RCS file:
>/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletcache/Cacheable.java,v
>retrieving revision 1.3
>diff -c -r1.3 Cacheable.java
>*** services/portletcache/Cacheable.java	2001/06/04 17:30:37	1.3
>--- services/portletcache/Cacheable.java	2001/10/05 23:22:35
>***************
>*** 103,107 ****
>--- 103,120 ----
>      */
>      public void setHandle( String handle );
>    
>+     /**
>+      * Return the expiration time in milliseconds.
>+      @return Expiration time in milliseconds since epoch, or null if
>the 
>+      *         expiration was not set
>+      */
>+     public Long getExpirationMillis();
>+ 
>+     /**
>+     * Set the expiration time in milliseconds.
>+     @param setExpirationMillis Expiration in milliseconds since epoch
>+     */
>+     public void setExpirationMillis( long expirationMillis);
>+ 
>  
>  }
>Index: services/portletcache/JetspeedPortletCacheService.java
>===================================================================
>RCS file:
>/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/portletcache/JetspeedPortletCacheService.java,v
>retrieving revision 1.4
>diff -c -r1.4 JetspeedPortletCacheService.java
>*** services/portletcache/JetspeedPortletCacheService.java	2001/03/07
>06:48:50	1.4
>--- services/portletcache/JetspeedPortletCacheService.java	2001/10/05
>23:22:35
>***************
>*** 108,115 ****
>          }
>          
>          if ( item.isCacheable() ) {
>!             GlobalCache.addObject( handle, new CachedObject( item ) );
>!         }
>  
>      }
>      
>--- 108,125 ----
>          }
>          
>          if ( item.isCacheable() ) {
>!             Long expirationMillis = item.getExpirationMillis();
>!             if (expirationMillis != null) {
>!               // Only cache objects that have not expired.
>!               if (System.currentTimeMillis() <
>expirationMillis.longValue()) {
>!                 GlobalCache.addObject( handle, new CachedObject( item,
>expirationMillis.longValue() - System.currentTimeMillis()) );
>!               }
>!             } else {
>!               // Oject will be cached Turbine
>"cachedobject.defaultage"
>!               GlobalCache.addObject( handle, new CachedObject( item )
>);
>!             }
>!       }
>! 
>  
>      }
>      
>Index: portal/portlets/AbstractPortlet.java
>===================================================================
>RCS file:
>/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/AbstractPortlet.java,v
>retrieving revision 1.45
>diff -c -r1.45 AbstractPortlet.java
>*** portal/portlets/AbstractPortlet.java	2001/09/10 22:41:00	1.45
>--- portal/portlets/AbstractPortlet.java	2001/10/05 23:22:36
>***************
>*** 111,116 ****
>--- 111,122 ----
>      private String        handle          = "";
>  
>      /**
>+     Expiration time of object in milliseconds since the standard base
>time
>+     known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
>+     */
>+     private Long          expirationMillis = null;
>+ 
>+     /**
>      Holds instances of ConcreteElements (Portlet output/content) 
>      based on its current CapabilityMap.
>      */
>***************
>*** 201,206 ****
>--- 207,227 ----
>      */
>      public final void setHandle( String handle ) {
>          this.handle = handle;
>+     }
>+ 
>+     /**
>+     @see Cacheable#getExpirationMillis
>+     */
>+     public Long getExpirationMillis() {
>+       return this.expirationMillis;
>+     }
>+     
>+ 
>+     /**
>+     @see Cacheable#setExpirationMillis
>+     */
>+     public void setExpirationMillis( long expirationMillis) {
>+       this.expirationMillis = new Long(expirationMillis);
>      }
>  
>      /** Builds a new cache handle for this cacheable class with the
>specified
>Index: portal/portlets/WebPagePortlet.java
>===================================================================
>RCS file:
>/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/WebPagePortlet.java,v
>retrieving revision 1.2
>diff -c -r1.2 WebPagePortlet.java
>*** portal/portlets/WebPagePortlet.java	2001/03/07 06:47:17	1.2
>--- portal/portlets/WebPagePortlet.java	2001/10/05 23:22:37
>***************
>*** 128,139 ****
>      
>      /**
>       * took this from FileServerPortlet as it was private 
>      */
>      private String getURL(String url) throws IOException {
>  
>          int CAPACITY = 1024;
>  
>!         InputStream is = new URL( url ).openStream();
>          ByteArrayOutputStream buffer = new ByteArrayOutputStream();
>  
>          //now process the InputStream...
>--- 128,145 ----
>      
>      /**
>       * took this from FileServerPortlet as it was private 
>+      *
>+      * FIXME: Currently only the expiration the HTTP Reponse header is
>honored. 
>+      *        Expiration information in <meta> tags are not honored 
>      */
>      private String getURL(String url) throws IOException {
>  
>          int CAPACITY = 1024;
>+         URL            pageUrl = new URL(url);
>+         URLConnection  pageConn = pageUrl.openConnection();
>+         long           pageExpiration = pageConn.getExpiration();
>  
>!         InputStream is = pageUrl.openStream();
>          ByteArrayOutputStream buffer = new ByteArrayOutputStream();
>  
>          //now process the InputStream...
>***************
>*** 147,152 ****
>--- 153,163 ----
>  
>          is.close();
>  
>+         // Only set the page expiration it the page has not expired
>+         if (pageExpiration > System.currentTimeMillis()) {
>+           Log.debug( "WebPagePortlet caching URL: " + url + "
>Expiration: " + pageExpiration);
>+           setExpirationMillis(pageExpiration);
>+         }
>  
>          return buffer.toString();
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org
>




---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org