You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2004/09/29 04:35:20 UTC
svn commit: rev 47445 - cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl
Author: vgritsenko
Date: Tue Sep 28 19:35:19 2004
New Revision: 47445
Modified:
cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
Log:
remove cachedLastModified
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java Tue Sep 28 19:35:19 2004
@@ -40,7 +40,7 @@
/**
* This is the base class for all caching pipeline implementations
- * that check the different pipeline components.
+ * that check different pipeline components.
*
* @since 2.1
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
@@ -48,7 +48,7 @@
* @version CVS $Id$
*/
public abstract class AbstractCachingProcessingPipeline
- extends BaseCachingProcessingPipeline {
+ extends BaseCachingProcessingPipeline {
/** The role name of the generator */
protected String generatorRole;
@@ -64,8 +64,6 @@
/** The cached response */
protected CachedResponse cachedResponse;
- /** The timestamp of the cached byte stream */
- protected long cachedLastModified;
/** The index indicating the first transformer getting input from the cache */
protected int firstProcessedTransformerIndex;
@@ -169,7 +167,7 @@
if (this.cachedResponse != null && this.completeResponseIsCached) {
// Allow for 304 (not modified) responses in dynamic content
- if (checkIfModified(environment, this.cachedLastModified)) {
+ if (checkIfModified(environment, this.cachedResponse.getLastModified())) {
return true;
}
@@ -278,8 +276,6 @@
this.toCacheKey = null;
- Serializable key = null;
-
this.firstNotCacheableTransformerIndex = 0;
this.cacheCompleteResponse = false;
@@ -290,6 +286,7 @@
// to build a unique key of the request
// is the generator cacheable?
+ Serializable key = null;
if (super.generator instanceof CacheableProcessingComponent) {
key = ((CacheableProcessingComponent)super.generator).getKey();
}
@@ -305,11 +302,9 @@
final int transformerSize = super.transformers.size();
boolean continueTest = true;
- while (this.firstNotCacheableTransformerIndex < transformerSize
- && continueTest) {
+ while (this.firstNotCacheableTransformerIndex < transformerSize && continueTest) {
final Transformer trans =
- (Transformer)super.transformers.get(
- this.firstNotCacheableTransformerIndex);
+ (Transformer) super.transformers.get(this.firstNotCacheableTransformerIndex);
key = null;
if (trans instanceof CacheableProcessingComponent) {
key = ((CacheableProcessingComponent)trans).getKey();
@@ -330,7 +325,7 @@
// all transformers are cacheable => pipeline is cacheable
// test serializer if this is not an internal request
if (this.firstNotCacheableTransformerIndex == transformerSize
- && super.serializer == this.lastConsumer) {
+ && super.serializer == this.lastConsumer) {
key = null;
if (super.serializer instanceof CacheableProcessingComponent) {
@@ -408,29 +403,24 @@
/**
* Calculate the key that can be used to get something from the cache, and
* handle expires properly.
- *
*/
protected void validatePipeline(Environment environment)
throws ProcessingException {
this.completeResponseIsCached = this.cacheCompleteResponse;
this.fromCacheKey = this.toCacheKey.copy();
this.firstProcessedTransformerIndex = this.firstNotCacheableTransformerIndex;
- this.cachedLastModified = 0L;
boolean finished = false;
-
while (this.fromCacheKey != null && !finished) {
-
finished = true;
- final CachedResponse response = this.cache.get( this.fromCacheKey );
+
+ final CachedResponse response = this.cache.get(this.fromCacheKey);
// now test validity
if (response != null) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Found cached response for '" + environment.getURI() +
- "' using key: " + this.fromCacheKey
- );
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Found cached response for '" + environment.getURI() +
+ "' using key: " + this.fromCacheKey);
}
boolean responseIsValid = true;
@@ -441,28 +431,22 @@
Long responseExpires = response.getExpires();
if (responseExpires != null) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Expires time found for " +
- environment.getURI());
- }
- if ( responseExpires.longValue() > System.currentTimeMillis()) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Expires time still fresh for " +
- environment.getURI() +
- ", ignoring all other cache settings. This entry expires on "+
- new Date(responseExpires.longValue()));
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Expires time found for " + environment.getURI());
+ }
+
+ if (responseExpires.longValue() > System.currentTimeMillis()) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Expires time still fresh for " + environment.getURI() +
+ ", ignoring all other cache settings. This entry expires on "+
+ new Date(responseExpires.longValue()));
}
this.cachedResponse = response;
- this.cachedLastModified = response.getLastModified();
return;
} else {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Expires time has expired for " +
- environment.getURI() +
- " regenerating content.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Expires time has expired for " + environment.getURI() +
+ ", regenerating content.");
}
// If an expires parameter was provided, use it. If this parameter is not available
@@ -492,14 +476,14 @@
int i = 0;
while (responseIsValid && i < fromCacheValidityObjects.length) {
boolean isValid = false;
+
// BH check if validities[i] is null, may happen
// if exception was thrown due to malformed content
SourceValidity validity = fromCacheValidityObjects[i];
int valid = validity != null ? validity.isValid() : -1;
- if ( valid == 0) { // don't know if valid, make second test
+ if (valid == 0) { // don't know if valid, make second test
validity = this.getValidityForInternalPipeline(i);
-
if (validity != null) {
valid = fromCacheValidityObjects[i].isValid( validity );
if (valid == 0) {
@@ -511,34 +495,40 @@
} else {
isValid = (valid == 1);
}
+
if (!isValid) {
responseIsValid = false;
// update validity
if (validity == null) {
responseIsUsable = false;
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("validatePipeline: responseIsUsable is false, valid==" + valid + " at index " + i);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("validatePipeline: responseIsUsable is false, valid=" +
+ valid + " at index " + i);
}
} else {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("validatePipeline: responseIsValid is false due to " + validity);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("validatePipeline: responseIsValid is false due to " +
+ validity);
}
}
} else {
i++;
}
}
+
if (responseIsValid) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("validatePipeline: using valid cached content for '" + environment.getURI() + "'.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("validatePipeline: using valid cached content for '" +
+ environment.getURI() + "'.");
}
+
// we are valid, ok that's it
this.cachedResponse = response;
- this.cachedLastModified = response.getLastModified();
this.toCacheSourceValidities = fromCacheValidityObjects;
} else {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("validatePipeline: cached content is invalid for '" + environment.getURI() + "'.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("validatePipeline: cached content is invalid for '" +
+ environment.getURI() + "'.");
}
// we are not valid!
@@ -658,7 +648,7 @@
readerKey = ((CacheableProcessingComponent)super.reader).getKey();
}
- if ( readerKey != null) {
+ if (readerKey != null) {
// response is cacheable, build the key
pcKey = new PipelineCacheKey();
pcKey.addKey(new ComponentCacheKey(ComponentCacheKey.ComponentType_Reader,
@@ -667,25 +657,22 @@
);
// now we have the key to get the cached object
- CachedResponse cachedObject = this.cache.get( pcKey );
-
+ CachedResponse cachedObject = this.cache.get(pcKey);
if (cachedObject != null) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Found cached response for '" +
- environment.getURI() + "' using key: " + pcKey);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Found cached response for '" +
+ environment.getURI() + "' using key: " + pcKey);
}
+
SourceValidity[] validities = cachedObject.getValidityObjects();
if (validities == null || validities.length != 1) {
// to avoid getting here again and again, we delete it
this.cache.remove( pcKey );
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
- "Cached response for '" +
- environment.getURI() + "' using key: " +
- pcKey + " is invalid.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Cached response for '" + environment.getURI() +
+ "' using key: " + pcKey + " is invalid.");
}
- cachedResponse = null;
+ this.cachedResponse = null;
} else {
SourceValidity cachedValidity = validities[0];
int result = cachedValidity.isValid();
@@ -706,8 +693,9 @@
}
if (valid) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("processReader: using valid cached content for '" + environment.getURI() + "'.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("processReader: using valid cached content for '" +
+ environment.getURI() + "'.");
}
byte[] response = cachedObject.getResponse();
if (response.length > 0) {
@@ -722,8 +710,9 @@
outputStream.write(response);
}
} else {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("processReader: cached content is invalid for '" + environment.getURI() + "'.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("processReader: cached content is invalid for '" +
+ environment.getURI() + "'.");
}
// remove invalid cached object
this.cache.remove(pcKey);
@@ -733,14 +722,16 @@
}
if (!usedCache) {
-
- if ( pcKey != null ) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("processReader: caching content for further requests of '" + environment.getURI() + "'.");
+ if (pcKey != null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("processReader: caching content for further requests of '" +
+ environment.getURI() + "'.");
}
+
if (readerValidity == null) {
readerValidity = ((CacheableProcessingComponent)super.reader).getValidity();
}
+
if (readerValidity != null) {
outputStream = environment.getOutputStream(this.outputBufferSize);
outputStream = new CachingOutputStream(outputStream);
@@ -749,7 +740,7 @@
}
}
- this.setMimeTypeForReader(environment);
+ setMimeTypeForReader(environment);
if (this.reader.shouldSetContentLength()) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
this.reader.setOutputStream(os);
@@ -758,7 +749,7 @@
if (outputStream == null) {
outputStream = environment.getOutputStream(0);
}
- os.writeTo(environment.getOutputStream(0));
+ os.writeTo(outputStream);
} else {
if (outputStream == null) {
outputStream = environment.getOutputStream(this.outputBufferSize);
@@ -769,13 +760,10 @@
// store the response
if (pcKey != null) {
- final CachedResponse res = new CachedResponse( new SourceValidity[] {readerValidity},
+ final CachedResponse res = new CachedResponse(new SourceValidity[] {readerValidity},
((CachingOutputStream)outputStream).getContent());
res.setContentType(environment.getContentType());
- this.cache.store(
- pcKey,
- res
- );
+ this.cache.store(pcKey, res);
}
}
} catch (Exception e) {
@@ -889,7 +877,6 @@
super.recycle();
}
-
}
final class DeferredPipelineValidity implements DeferredValidity {