You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/05/15 09:51:36 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/components/pipeline CacheableEventPipeline.java CachingEventPipeline.java CachingStreamPipeline.java

cziegeler    01/05/15 00:51:35

  Modified:    src/org/apache/cocoon/components/pipeline
                        CacheableEventPipeline.java
                        CachingEventPipeline.java
                        CachingStreamPipeline.java
  Log:
  Update caching logic for a later implementation of cacheable content aggregation
  
  Revision  Changes    Path
  1.2       +7 -1      xml-cocoon2/src/org/apache/cocoon/components/pipeline/CacheableEventPipeline.java
  
  Index: CacheableEventPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/CacheableEventPipeline.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CacheableEventPipeline.java	2001/05/09 20:49:46	1.1
  +++ CacheableEventPipeline.java	2001/05/15 07:51:23	1.2
  @@ -16,7 +16,7 @@
    *
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/09 20:49:46 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/05/15 07:51:23 $
    */
   public interface CacheableEventPipeline {
   
  @@ -42,4 +42,10 @@
        *         not cacheable.
        */
       Map generateValidity(Environment environment) throws Exception;
  +
  +    /**
  +     * The stream pipeline (or the content aggregator) calls this
  +     * method to tell the event pipeline if it must not cache the result
  +     */
  +    void setStreamPipelineCaches(boolean flag);
   }
  
  
  
  1.4       +13 -4     xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingEventPipeline.java
  
  Index: CachingEventPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingEventPipeline.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CachingEventPipeline.java	2001/05/14 09:16:19	1.3
  +++ CachingEventPipeline.java	2001/05/15 07:51:26	1.4
  @@ -53,7 +53,7 @@
    * does not cache! (If it would cache, the response would be cached twice!)
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2001/05/14 09:16:19 $
  + * @version CVS $Revision: 1.4 $ $Date: 2001/05/15 07:51:26 $
    */
   public final class CachingEventPipeline
   extends AbstractEventPipeline
  @@ -124,13 +124,22 @@
        */
       public Map generateValidity(Environment environment)
       throws Exception {
  -        // if we are cacheable and this method is called
  -        // reset the pipeline cache key to avoid duplicate caching
           if (this.cacheable == true) {
  -            this.pipelineCacheKey = null;
               return this.validityObjects;
           }
           return null;
  +    }
  +
  +    /**
  +     * The stream pipeline (or the content aggregator) calls this
  +     * method to tell the event pipeline if it must not cache the result
  +     */
  +    public void setStreamPipelineCaches(boolean flag) {
  +        // if we are cacheable and this method is called
  +        // reset the pipeline cache key to avoid duplicate caching
  +        if (flag == true) {
  +            this.pipelineCacheKey = null;
  +        }
       }
   
       public boolean process(Environment environment) throws Exception {
  
  
  
  1.2       +59 -52    xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingStreamPipeline.java
  
  Index: CachingStreamPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingStreamPipeline.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CachingStreamPipeline.java	2001/05/09 20:49:48	1.1
  +++ CachingStreamPipeline.java	2001/05/15 07:51:28	1.2
  @@ -46,7 +46,7 @@
    *  </ul>
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/09 20:49:48 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/05/15 07:51:28 $
    */
   public class CachingStreamPipeline extends AbstractStreamPipeline {
   
  @@ -267,66 +267,72 @@
                   PipelineCacheKey eventPipelineKey = null;
                   CacheValidity serializerValidity = null;
                   Map eventPipelineValidity = null;
  -                if (this.serializer instanceof Cacheable
  -                    && this.eventPipeline instanceof CacheableEventPipeline
  -                    && (serializerKey = ((Cacheable)this.serializer).generateKey()) != 0
  -                    && (serializerValidity = ((Cacheable)this.serializer).generateValidity()) != null
  -                    && (eventPipelineKey = ((CacheableEventPipeline)this.eventPipeline).generateKey(environment)) != null
  -                    && (eventPipelineValidity = ((CacheableEventPipeline)this.eventPipeline).generateValidity(environment)) != null) {
  -
  -                    // response is cacheable, build the key
  -                    validityObjects = eventPipelineValidity;
  -                    ComponentCacheKey ccKey;
  -                    pcKey = new PipelineCacheKey();
  -                    ccKey = new ComponentCacheKey(ComponentCacheKey.ComponentType_Serializer,
  +                if (this.eventPipeline instanceof CacheableEventPipeline) {
  +                    if (this.serializer instanceof Cacheable
  +                        && (serializerKey = ((Cacheable)this.serializer).generateKey()) != 0
  +                        && (serializerValidity = ((Cacheable)this.serializer).generateValidity()) != null
  +                        && (eventPipelineKey = ((CacheableEventPipeline)this.eventPipeline).generateKey(environment)) != null
  +                        && (eventPipelineValidity = ((CacheableEventPipeline)this.eventPipeline).generateValidity(environment)) != null) {
  +
  +                        // tell the event pipeline that it must not cache
  +                        ((CacheableEventPipeline)this.eventPipeline).setStreamPipelineCaches(true);
  +
  +                        // response is cacheable, build the key
  +                        validityObjects = eventPipelineValidity;
  +                        ComponentCacheKey ccKey;
  +                        pcKey = new PipelineCacheKey();
  +                        ccKey = new ComponentCacheKey(ComponentCacheKey.ComponentType_Serializer,
                                                       this.serializerRole,
                                                       serializerKey);
  -                    validityObjects.put(ccKey, serializerValidity);
  -                    pcKey.addKey(ccKey);
  -                    pcKey.addKey(eventPipelineKey);
  -
  -                    // now we have the key to get the cached object
  -                    CachedStreamObject cachedObject = (CachedStreamObject)this.streamCache.get(pcKey);
  -
  -                    if (cachedObject != null) {
  -                        getLogger().debug("Found cached response for '" + environment.getURI() + "'.");
  -
  -                        Iterator validityIterator = validityObjects.keySet().iterator();
  -                        ComponentCacheKey validityKey;
  -                        boolean valid = true;
  -                        while (validityIterator.hasNext() == true && valid == true) {
  -                            validityKey = (ComponentCacheKey)validityIterator.next();
  -                            valid = cachedObject.isValid(validityKey, (CacheValidity)validityObjects.get(validityKey));
  -                            if (getLogger().isDebugEnabled() == true) {
  -                                CacheValidity cachedValidity = cachedObject.getCacheValidity(validityKey);
  -                                getLogger().debug("Compared cached validity '" + cachedValidity +
  -                                    "' with new validity '" + validityObjects.get(validityKey) +
  -                                    "' : " + (valid == true ? "valid" : "changed"));
  +                        validityObjects.put(ccKey, serializerValidity);
  +                        pcKey.addKey(ccKey);
  +                        pcKey.addKey(eventPipelineKey);
  +
  +                        // now we have the key to get the cached object
  +                        CachedStreamObject cachedObject = (CachedStreamObject)this.streamCache.get(pcKey);
  +
  +                        if (cachedObject != null) {
  +                            getLogger().debug("Found cached response for '" + environment.getURI() + "'.");
  +
  +                            Iterator validityIterator = validityObjects.keySet().iterator();
  +                            ComponentCacheKey validityKey;
  +                            boolean valid = true;
  +                            while (validityIterator.hasNext() == true && valid == true) {
  +                                validityKey = (ComponentCacheKey)validityIterator.next();
  +                                valid = cachedObject.isValid(validityKey, (CacheValidity)validityObjects.get(validityKey));
  +                                if (getLogger().isDebugEnabled() == true) {
  +                                    CacheValidity cachedValidity = cachedObject.getCacheValidity(validityKey);
  +                                    getLogger().debug("Compared cached validity '" + cachedValidity +
  +                                        "' with new validity '" + validityObjects.get(validityKey) +
  +                                        "' : " + (valid == true ? "valid" : "changed"));
  +                                }
                               }
  -                        }
  -                        if (valid == true) {
  +                            if (valid == true) {
   
  -                            getLogger().debug("Using valid cached content for '" + environment.getURI() + "'.");
  -                            byte[] bytes = cachedObject.getResponse();
  -                            if(bytes.length > 0) {
  -                                usedCache = true;
  -                                environment.setContentLength(bytes.length);
  -                                outputStream.write(bytes);
  +                                getLogger().debug("Using valid cached content for '" + environment.getURI() + "'.");
  +                                byte[] bytes = cachedObject.getResponse();
  +                                if(bytes.length > 0) {
  +                                    usedCache = true;
  +                                    environment.setContentLength(bytes.length);
  +                                    outputStream.write(bytes);
  +                                }
                               }
  -                        }
   
  -                        if (usedCache == false) {
  +                            if (usedCache == false) {
   
  -                            getLogger().debug("Cached content is invalid for '" + environment.getURI() + "'.");
  +                                getLogger().debug("Cached content is invalid for '" + environment.getURI() + "'.");
   
  -                            // remove invalid cached object
  -                            this.streamCache.remove(pcKey);
  -                            cachedObject = null;
  +                                // remove invalid cached object
  +                                this.streamCache.remove(pcKey);
  +                                cachedObject = null;
  +                            }
                           }
  -                    }
  -                    if (cachedObject == null) {
  -                        getLogger().debug("Caching content for further requests of '" + environment.getURI() + "'.");
  -                        outputStream = new CachingOutputStream(outputStream);
  +                        if (cachedObject == null) {
  +                            getLogger().debug("Caching content for further requests of '" + environment.getURI() + "'.");
  +                            outputStream = new CachingOutputStream(outputStream);
  +                        }
  +                    } else {
  +                        ((CacheableEventPipeline)this.eventPipeline).setStreamPipelineCaches(false);
                       }
                   }
   
  @@ -346,6 +352,7 @@
                           this.streamCache.store(pcKey,
                               new CachedStreamObject(validityObjects, bytes));
                       }
  +
                   }
   
               } catch ( Exception e ) {
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org