Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 2443 invoked from network); 19 Aug 2004 13:21:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 19 Aug 2004 13:21:37 -0000 Received: (qmail 9027 invoked by uid 500); 19 Aug 2004 13:21:37 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 8917 invoked by uid 500); 19 Aug 2004 13:21:35 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 8869 invoked by uid 99); 19 Aug 2004 13:21:35 -0000 X-ASF-Spam-Status: No, hits=-2.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Thu, 19 Aug 2004 06:21:33 -0700 Received: (qmail 2351 invoked by uid 65534); 19 Aug 2004 13:21:31 -0000 Date: 19 Aug 2004 13:21:31 -0000 Message-ID: <20040819132131.2349.qmail@minotaur.apache.org> From: unico@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 36609 - cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: unico Date: Thu Aug 19 06:21:30 2004 New Revision: 36609 Modified: cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/CachingSource.java Log: use event validity when cache is instance of event aware Modified: cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/CachingSource.java ============================================================================== --- cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/CachingSource.java (original) +++ cocoon/trunk/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/CachingSource.java Thu Aug 19 06:21:30 2004 @@ -29,7 +29,10 @@ import org.apache.cocoon.CascadingIOException; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.caching.Cache; +import org.apache.cocoon.caching.EventAware; import org.apache.cocoon.caching.IdentifierCacheKey; +import org.apache.cocoon.caching.validity.EventValidity; +import org.apache.cocoon.caching.validity.NamedEvent; import org.apache.cocoon.components.sax.XMLDeserializer; import org.apache.cocoon.components.sax.XMLSerializer; import org.apache.cocoon.xml.ContentHandlerWrapper; @@ -66,7 +69,7 @@ * always. 0 can be used to achieve the exact opposite. That is to say, * the cached contents will be thrown out and updated immediately and unconditionally. *

- * @version CVS $Id: CachingSource.java,v 1.13 2004/07/01 14:24:36 unico Exp $ + * @version CVS $Id$ */ public class CachingSource extends AbstractLogEnabled implements Source, Serviceable, Initializable, XMLizable { @@ -206,7 +209,14 @@ boolean storeResponse = false; CachedSourceResponse response = this.response; if (response == null) { - response = new CachedSourceResponse(new SourceValidity[] { new ExpiresValidity(getExpiration()), source.getValidity() }); + SourceValidity[] validities; + if (this.cache instanceof EventAware) { + validities = new SourceValidity[] { new EventValidity(new NamedEvent(this.source.getURI())) }; + } + else { + validities = new SourceValidity[] { new ExpiresValidity(getExpiration()), source.getValidity() }; + } + response = new CachedSourceResponse(validities); storeResponse = true; } if (response.getExtra() == null) { @@ -573,32 +583,40 @@ private boolean checkValidity() { if (this.response == null) return false; - final ExpiresValidity expiresValidity = (ExpiresValidity) this.response.getValidityObjects()[0]; - final SourceValidity sourceValidity = this.response.getValidityObjects()[1]; - + final SourceValidity[] validities = this.response.getValidityObjects(); boolean valid = true; - - if (expiresValidity.isValid() != SourceValidity.VALID) { - if (getLogger().isDebugEnabled()) { - getLogger().debug("Cached response of source " + getSourceURI() + " is expired."); - } - if (!isValid(sourceValidity, source.getValidity())) { + if (validities.length == 2) { + final ExpiresValidity expiresValidity = (ExpiresValidity) validities[0]; + final SourceValidity sourceValidity = validities[1]; + + if (expiresValidity.isValid() != SourceValidity.VALID) { if (getLogger().isDebugEnabled()) { - getLogger().debug("Cached response of source " + getSourceURI() + " is invalid."); + getLogger().debug("Cached response of source " + getSourceURI() + " is expired."); + } + if (!isValid(sourceValidity, source.getValidity())) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Cached response of source " + getSourceURI() + " is invalid."); + } + valid = false; + } + else { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Cached response of source " + getSourceURI() + " is still valid."); + } + // set new expiration period + this.response.getValidityObjects()[0] = new ExpiresValidity(getExpiration()); } - valid = false; } else { if (getLogger().isDebugEnabled()) { - getLogger().debug("Cached response of source " + getSourceURI() + " is still valid."); + getLogger().debug("Cached response of source " + getSourceURI() + " is NOT expired."); } - // set new expiration period - this.response.getValidityObjects()[0] = new ExpiresValidity(getExpiration()); } } else { + // assert(validities.length == 1 && validities[0] instanceof EventValidity) if (getLogger().isDebugEnabled()) { - getLogger().debug("Cached response of source " + getSourceURI() + " is NOT expired."); + getLogger().debug("Cached response of source does not expire"); } } return valid;