cziegeler    02/05/28 03:51:31

  Modified:    src/java/org/apache/cocoon/caching ComponentCacheKey.java
                        PipelineCacheKey.java
               src/java/org/apache/cocoon/components/pipeline/impl
                        CachingProcessingPipeline.java
  Log:
  Minor updates
  
  Revision  Changes    Path
  1.8       +20 -1     
xml-cocoon2/src/java/org/apache/cocoon/caching/ComponentCacheKey.java
  
  Index: ComponentCacheKey.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/ComponentCacheKey.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ComponentCacheKey.java    28 May 2002 07:11:43 -0000      1.7
  +++ ComponentCacheKey.java    28 May 2002 10:51:31 -0000      1.8
  @@ -61,7 +61,7 @@
    *      is unique inside the components space.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Id: ComponentCacheKey.java,v 1.7 2002/05/28 07:11:43 cziegeler Exp 
$
  + * @version CVS $Id: ComponentCacheKey.java,v 1.8 2002/05/28 10:51:31 cziegeler Exp 
$
    */
   public final class ComponentCacheKey
       implements Serializable {
  @@ -77,7 +77,12 @@
       private String identifier;
       /** The unique key */
       private Serializable key;
  +    /** the hash code */
  +    private int hashCode = 0;
   
  +    /**
  +     * Constructor
  +     */
       public ComponentCacheKey(int          componentType,
                                String       componentIdentifier,
                                Serializable cacheKey) {
  @@ -87,6 +92,9 @@
   
       }
   
  +    /**
  +     * Compare
  +     */
       public boolean equals(Object object) {
           if (object instanceof ComponentCacheKey) {
               ComponentCacheKey ccp = (ComponentCacheKey)object;
  @@ -99,4 +107,15 @@
           return false;
       }
   
  +    /**
  +     * HashCode
  +     */
  +    public int hashCode() {
  +        if (this.hashCode == 0) {
  +            this.hashCode = this.type +
  +                            (this.identifier.length() << 2) +
  +                            (this.key.hashCode() << 6);
  +        }
  +        return this.hashCode;
  +    }
   }
  
  
  
  1.10      +16 -4     
xml-cocoon2/src/java/org/apache/cocoon/caching/PipelineCacheKey.java
  
  Index: PipelineCacheKey.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/PipelineCacheKey.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PipelineCacheKey.java     28 May 2002 08:42:12 -0000      1.9
  +++ PipelineCacheKey.java     28 May 2002 10:51:31 -0000      1.10
  @@ -58,7 +58,7 @@
    * or more {@link ComponentCacheKey}s.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Id: PipelineCacheKey.java,v 1.9 2002/05/28 08:42:12 cziegeler Exp $
  + * @version CVS $Id: PipelineCacheKey.java,v 1.10 2002/05/28 10:51:31 cziegeler Exp 
$
    */
   public final class PipelineCacheKey
       implements java.io.Serializable {
  @@ -66,6 +66,9 @@
       /** The keys */
       private List keys;
   
  +    /** the hash code */
  +    private int hashCode = 0;
  +
       /**
        * Constructor
        */
  @@ -78,6 +81,7 @@
        */
       public void addKey(ComponentCacheKey key) {
           this.keys.add(key);
  +        this.hashCode = 0;
       }
   
       /**
  @@ -85,6 +89,7 @@
        */
       public void removeLastKey() {
           this.keys.remove(this.keys.size()-1);
  +        this.hashCode = 0;
       }
   
       /**
  @@ -102,7 +107,7 @@
               PipelineCacheKey pck = (PipelineCacheKey)object;
               final int len = this.keys.size();
               if (pck.keys.size() == len) {
  -                boolean cont = false;
  +                boolean cont = true;
                   int i = 0;
                   while (i < len && cont) {
                       cont = this.keys.get(i).equals(pck.keys.get(i));
  @@ -118,10 +123,17 @@
        * Generate a hash code
        */
       public int hashCode() {
  -        // FIXME (CZ) we need a good one here...
  -        return this.keys.hashCode();
  +        if (this.hashCode == 0) {
  +            for(int i=0; i < this.keys.size(); i++) {
  +                this.hashCode = this.keys.get(i).hashCode();
  +            }
  +        }
  +        return this.hashCode;
       }
   
  +    /**
  +     * Clone the object (but not the component keys)
  +     */
       public PipelineCacheKey copy() {
           PipelineCacheKey pck = new PipelineCacheKey();
           final int len = this.keys.size();
  
  
  
  1.18      +43 -12    
xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
  
  Index: CachingProcessingPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CachingProcessingPipeline.java    28 May 2002 09:06:33 -0000      1.17
  +++ CachingProcessingPipeline.java    28 May 2002 10:51:31 -0000      1.18
  @@ -92,7 +92,7 @@
    *
    * @since @next-version@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Id: CachingProcessingPipeline.java,v 1.17 2002/05/28 09:06:33 
cziegeler Exp $
  + * @version CVS $Id: CachingProcessingPipeline.java,v 1.18 2002/05/28 10:51:31 
cziegeler Exp $
    */
   public class CachingProcessingPipeline
   extends AbstractProcessingPipeline
  @@ -206,6 +206,10 @@
               }
           } else {
   
  +            if (this.getLogger().isDebugEnabled()) {
  +                this.getLogger().debug("Caching content for further requests of '" 
+ environment.getURI() + "'.");
  +                System.out.println("Caching content for further requests of '" + 
environment.getURI() + "'.");
  +            }
               try {
                   OutputStream os = environment.getOutputStream();
                   if ( this.completeResponseIsCached ) {
  @@ -235,20 +239,18 @@
                           this.generator.generate();
                       }
                   }
  -                if (this.xmlSerializer != null) {
  -                    if ( this.completeResponseIsCached ) {
  -                        CachedResponse response = new 
CachedResponse(this.pipelineValidityObjects,
  +                if ( this.completeResponseIsCached ) {
  +                    CachedResponse response = new 
CachedResponse(this.pipelineValidityObjects,
                                        ((CachingOutputStream)os).getContent());
  -                        this.cache.store(environment.getObjectModel(),
  +                    this.cache.store(environment.getObjectModel(),
                                            this.pipelineCacheKey,
                                            response);
  -                    } else {
  -                        CachedResponse response = new 
CachedResponse(this.pipelineValidityObjects,
  +                } else {
  +                    CachedResponse response = new 
CachedResponse(this.pipelineValidityObjects,
                                        (byte[])this.xmlSerializer.getSAXFragment());
  -                        this.cache.store(environment.getObjectModel(),
  +                     this.cache.store(environment.getObjectModel(),
                                            this.pipelineCacheKey,
                                            response);
  -                    }
                   }
               } catch ( SocketException se ) {
                   if (se.getMessage().indexOf("reset") > 0
  @@ -288,6 +290,7 @@
           this.firstProcessedTransformerIndex = 0;
           this.completeResponseIsCached = false;
   
  +        System.out.println("Generating key.");
           // first step is to generate the key:
           // All pipeline components starting with the generator
           // are tested if they are either a CacheableProcessingComponent
  @@ -355,6 +358,7 @@
               }
           }
   
  +        System.out.println("Generated key:"+processingPipelineKey);
           // now, we have a key representing all cacheable components up to the
           // first non cacheable
           if (processingPipelineKey != null) {
  @@ -369,9 +373,13 @@
   
               // now test validity
               if (response != null) {
  -                this.cachedResponse = response.getResponse();
                   boolean responseIsValid = true;
                   boolean responseIsUsable = true;
  +                if (this.getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug("Found cached response for '" + 
environment.getURI() + "'.");
  +                   System.out.println("Found cached response for '" + 
environment.getURI() + "'.");
  +                }
  +                this.cachedResponse = response.getResponse();
                   SourceValidity[] validities = response.getValidityObjects();
                   int i = 0;
                   while (responseIsValid && i < validities.length) {
  @@ -385,7 +393,7 @@
                               } else {
                                   validity = new 
CacheValidityToSourceValidity(((Cacheable)super.generator).generateValidity());
                               }
  -                        } else if (i <= this.firstProcessedTransformerIndex + 1) {
  +                        } else if (i <= this.firstProcessedTransformerIndex) {
                               // test transformer
                               final Transformer trans =
                                  (Transformer)super.transformers.get(i-1);
  @@ -418,7 +426,15 @@
                   if ( responseIsValid ) {
                       // we are valid, ok that's it
                       cachedValidityObjects = validities;
  +                    if (this.getLogger().isDebugEnabled()) {
  +                        this.getLogger().debug("Using valid cached content for '" + 
environment.getURI() + "'.");
  +                        System.out.println("Using valid cached content for '" + 
environment.getURI() + "'.");
  +                    }
                   } else {
  +                    if (this.getLogger().isDebugEnabled()) {
  +                        this.getLogger().debug("Cached content is invalid for '" + 
environment.getURI() + "'.");
  +                        System.out.println("Cached content is invalid for '" + 
environment.getURI() + "'.");
  +                    }
                       // we are not valid!
                       this.completeResponseIsCached = false;
                       finished = false;
  @@ -451,6 +467,21 @@
                           cachedPipelineKey = null;
                       }
                   }
  +            } else {
  +                if (this.getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug("Cached response not found for '" + 
environment.getURI() + "'.");
  +                    System.out.println("Cached response not found for '" + 
environment.getURI() + "'.");
  +                }
  +                finished = false;
  +                this.completeResponseIsCached = false;
  +                // try a shorter key
  +                // FIXME (CZ) calculation of PPK
  +                if (cachedPipelineKey.size() > 1) {
  +                    cachedPipelineKey.removeLastKey();
  +                    this.firstProcessedTransformerIndex--;
  +                } else {
  +                    cachedPipelineKey = null;
  +                }
               }
           }
   
  @@ -476,7 +507,7 @@
                           } else {
                               validity = new 
CacheValidityToSourceValidity(((Cacheable)super.generator).generateValidity());
                           }
  -                    } else if (i <= firstNotCacheableTransformerIndex + 1) {
  +                    } else if (i <= firstNotCacheableTransformerIndex) {
                           // test transformer
                           final Transformer trans =
                              (Transformer)super.transformers.get(i-1);
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to