cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miles Elam <mi...@pcextremist.com>
Subject Last-Modified and If-Modified-Since on pipelines
Date Sat, 19 Apr 2003 20:08:21 GMT
I added a last modified (long value) property to the CachedResponse 
object so that the environment and servlet engine could respond to 
If-Modified-Since headers and reduce network traffic.  The idea being 
that the cached response, a byte array, comprised the last valid 
timestamp for the entire matcher/request.  It doesn't apply to any 
specific resource in the pipelines and matchers and so has no component 
author-accessible methods and is immutable.

I've only tested it on the default front welcome page (simple 
XML->XSLT->XHTML) with wget, but it seems to work just fine.  The first 
access doesn't set Last-Modified just as it doesn't set Content-Length;  
The stream wasn't buffered on the first access.  However, all subsequent 
accesses have the header, and if the client sends an If-Modified-Since 
header, a 304 with no body is sent correctly.  Changing any piece of the 
pipeline correctly invalidated the cache and regenerated the 
CachedResponse object (with a new timestamp), so no regressions in that 
case that I can see.

Simple patches but one that folks behind a proxy or limited bandwidth 
line might appreciate.

I was looking at adding ETag support (passing a hashed version of the 
cache key), but it would require changes to Environment, and I didn't 
know how folks felt about changing that particular interface.  It would 
involve adding

    boolean isResponseModified(String etag);

to compliment

    boolean isResponseModified(long lastModified);

adding another dummy method to AbstractEnvironment, and patching 
HttpEnvironment to check the If-None-Match header.  Missing anything?  
Should I just do it?

- Miles Elam



Index: AbstractProcessingPipeline.java
===================================================================
RCS file: 
/home/cvspublic/cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java,v
retrieving revision 1.1
diff -r1.1 AbstractProcessingPipeline.java
482c482
<             if (this.checkLastModified( environment )) {
---
 >             if (this.checkLastModified( environment, 
this.reader.getLastModified() )) {
579c579
<     protected boolean checkLastModified(Environment environment)
---
 >     protected boolean checkLastModified(Environment environment, long 
lastModified)
582d581
<         long lastModified = this.reader.getLastModified();


Index: AbstractCachingProcessingPipeline.java
===================================================================
RCS file: 
/home/cvspublic/cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java,v
retrieving revision 1.3
diff -r1.3 AbstractCachingProcessingPipeline.java
110a111,113
 >     /** The timestamp of the cached byte stream */
 >     protected long             cachedLastModified;
 >
215a219,224
 >
 >             // Allow for 304 (not modified) responses in dynamic content
 >             if (super.checkLastModified( environment, 
this.cachedLastModified )) {
 >                 return true;
 >             }
 >
459a469
 >         this.cachedLastModified = 0L;
498a509
 >                         this.cachedLastModified = response.lastModified;
534c545
<
---
 >
573a585
 >                     this.cachedLastModified = response.lastModified;


Index: CachedResponse.java
===================================================================
RCS file: 
/home/cvspublic/cocoon-2.1/src/java/org/apache/cocoon/caching/CachedResponse.java,v
retrieving revision 1.1
diff -r1.1 CachedResponse.java
73a74
 >     public  final long       lastModified;
86a88
 >         this.lastModified = 
this.setLastModified(System.currentTimeMillis());
103a106
 >         this.lastModified = 
this.setLastModified(System.currentTimeMillis());
136a140,150
 >     }
 >
 >     /**
 >      * Set the (newly) configured last modified.  Since last modified is
 >      *  dependant upon the time of caching and not the pipeline 
component(s),
 >      *  this method is not publically accessible nor is this.lastModified
 >      *   mutable.
 >      *
 >      */
 >     protected long setLastModified(long lastModified) {
 >         return (lastModified - (lastModified % 1000)); // Strip 
milliseconds



Mime
View raw message