cziegeler 2003/08/20 01:34:16
Modified: src/java/org/apache/cocoon/components/pipeline/impl
AbstractCachingProcessingPipeline.java
Log:
Don't throw an exception if the cached content is not correct. Just don't use it
Revision Changes Path
1.13 +48 -39
cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
Index: AbstractCachingProcessingPipeline.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- AbstractCachingProcessingPipeline.java 11 Aug 2003 07:33:08 -0000 1.12
+++ AbstractCachingProcessingPipeline.java 20 Aug 2003 08:34:16 -0000 1.13
@@ -719,50 +719,59 @@
}
SourceValidity[] validities = cachedObject.getValidityObjects();
if (validities == null || validities.length != 1) {
- throw new ProcessingException("Cached response is not
correct.");
- }
- SourceValidity cachedValidity = validities[0];
- int result = cachedValidity.isValid();
- boolean valid = false;
- if ( result == 0 ) {
- // get reader validity and compare
- if (isCacheableProcessingComponent) {
- readerValidity =
((CacheableProcessingComponent)super.reader).getValidity();
- } else {
- CacheValidity cv =
((Cacheable)super.reader).generateValidity();
- if ( cv != null ) {
- readerValidity =
CacheValidityToSourceValidity.createValidity( cv );
- }
+ // 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 (readerValidity != null) {
- result = cachedValidity.isValid(readerValidity);
- if ( result == 0 ) {
- readerValidity = null;
+ cachedResponse = null;
+ } else {
+ SourceValidity cachedValidity = validities[0];
+ int result = cachedValidity.isValid();
+ boolean valid = false;
+ if ( result == 0 ) {
+ // get reader validity and compare
+ if (isCacheableProcessingComponent) {
+ readerValidity =
((CacheableProcessingComponent)super.reader).getValidity();
} else {
- valid = (result == 1);
+ CacheValidity cv =
((Cacheable)super.reader).generateValidity();
+ if ( cv != null ) {
+ readerValidity =
CacheValidityToSourceValidity.createValidity( cv );
+ }
}
+ if (readerValidity != null) {
+ result = cachedValidity.isValid(readerValidity);
+ if ( result == 0 ) {
+ readerValidity = null;
+ } else {
+ valid = (result == 1);
+ }
+ }
+ } else {
+ valid = (result > 0);
}
- } else {
- valid = (result > 0);
- }
- if (valid) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("processReader: using valid
cached content for '" + environment.getURI() + "'.");
- }
- byte[] response = cachedObject.getResponse();
- if (response.length > 0) {
- usedCache = true;
- outputStream = environment.getOutputStream(0);
- environment.setContentLength(response.length);
- outputStream.write(response);
- }
- } else {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("processReader: cached content
is invalid for '" + environment.getURI() + "'.");
+ if (valid) {
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("processReader: using valid
cached content for '" + environment.getURI() + "'.");
+ }
+ byte[] response = cachedObject.getResponse();
+ if (response.length > 0) {
+ usedCache = true;
+ outputStream = environment.getOutputStream(0);
+ environment.setContentLength(response.length);
+ outputStream.write(response);
+ }
+ } else {
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("processReader: cached
content is invalid for '" + environment.getURI() + "'.");
+ }
+ // remove invalid cached object
+ this.cache.remove(pcKey);
}
- // remove invalid cached object
- this.cache.remove(pcKey);
}
}
}