You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/05/05 21:43:02 UTC

svn commit: r653569 - in /cocoon/whiteboard/corona/trunk: corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/ corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/ corona-sitemap/src/main/resources/META-INF/cocoon/spring/

Author: reinhard
Date: Mon May  5 12:43:01 2008
New Revision: 653569

URL: http://svn.apache.org/viewvc?rev=653569&view=rev
Log:
COCOON-2205

Apply a patch by Steven Dolg that introduced asynchronous caching:  When a pipeline is cached but the cache key is not valid anymore, the refresh is done in a separate thread. This is useful when refreshing shouldn't block the current request.

Compared to Cocoon 2.1/2.2, this doesn't require any additional refresh configurations.

Added:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java   (with props)
Modified:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheValue.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompleteCacheValue.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline.xml

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java Mon May  5 12:43:01 2008
@@ -68,10 +68,25 @@
         this.invokeStarter();
     }
 
+    public String getContentType() {
+        Finisher last = getFinisher();
+        return last.getContentType();
+    }
+
     protected LinkedList<PipelineComponent> getComponents() {
         return this.components;
     }
 
+    protected Finisher getFinisher() {
+        return (Finisher) this.components.getLast();
+    }
+
+    protected void invokeActions(Map<String, Object> parameters) throws Exception {
+        for (Action action : this.actions) {
+            action.execute(parameters);
+        }
+    }
+
     protected void invokeStarter() {
         Starter starter = (Starter) this.components.getFirst();
         starter.execute();
@@ -111,12 +126,6 @@
         ((Finisher) last).setOutputStream(outputStream);
     }
 
-    protected void invokeActions(Map<String, Object> parameters) throws Exception {
-        for (Action action : this.actions) {
-            action.execute(parameters);
-        }
-    }
-
     private void linkComponents(PipelineComponent firstComponent, PipelineComponent secondComponent) {
         // first component must be a Producer
         if (!(firstComponent instanceof Producer)) {
@@ -131,9 +140,4 @@
         // let the Producer accept the Consumer (the Producer might reject it)
         ((Producer) firstComponent).setConsumer((Consumer) secondComponent);
     }
-
-    public String getContentType() {
-        Finisher last = (Finisher) this.components.getLast();
-        return last.getContentType();
-    }
 }

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java?rev=653569&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java Mon May  5 12:43:01 2008
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.corona.pipeline;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.cocoon.corona.pipeline.caching.CacheKey;
+import org.apache.cocoon.corona.pipeline.caching.CacheRefreshJob;
+import org.apache.cocoon.corona.pipeline.caching.CacheRefreshManager;
+import org.apache.cocoon.corona.pipeline.caching.CacheValue;
+import org.apache.cocoon.corona.pipeline.caching.CachingOutputStream;
+import org.apache.cocoon.corona.pipeline.caching.CompleteCacheValue;
+
+public class AsyncCachePipeline extends CachingPipeline implements CacheRefreshJob {
+
+    private CacheRefreshManager cacheRefreshManager;
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.CachingPipeline#execute(java.util.Map, java.io.OutputStream)
+     */
+    @Override
+    public void execute(Map<String, Object> parameters, OutputStream outputStream) throws Exception {
+        this.invokeActions(parameters);
+
+        // create a caching output stream to intercept the result
+        CachingOutputStream cachingOutputStream = new CachingOutputStream(outputStream);
+        this.setupComponents(parameters, cachingOutputStream);
+
+        // construct the current cache key
+        CacheKey cacheKey = this.constructCacheKey();
+        // check for a cached value first
+        CacheValue cachedValue = this.getCachedValue(cacheKey);
+        if (cachedValue != null) {
+            // cached value found -> write it
+            cachedValue.writeTo(outputStream);
+
+            if (!cachedValue.isValid(cacheKey)) {
+                // the cached value is not valid -> refresh the value
+                this.cacheRefreshManager.refreshCacheValue(cacheKey, this);
+            }
+            // stop here
+            return;
+        }
+
+        // no cached value (not even an invalid one) was present -> execute the pipeline
+        this.invokeStarter();
+        // cache the result
+        this.setCachedValue(cacheKey, new CompleteCacheValue(cachingOutputStream.getContent(), cacheKey));
+    }
+
+    public CacheRefreshManager getCacheRefreshManager() {
+        return this.cacheRefreshManager;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.caching.CacheRefreshJob#refresh(org.apache.cocoon.corona.pipeline.caching.CacheKey)
+     */
+    public void refresh(CacheKey cacheKey) {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        this.getFinisher().setOutputStream(baos);
+
+        // execute the pipeline
+        this.invokeStarter();
+
+        this.setCachedValue(cacheKey, new CompleteCacheValue(baos.toByteArray(), cacheKey));
+    }
+
+    public void setCacheRefreshManager(CacheRefreshManager cacheRefreshManager) {
+        this.cacheRefreshManager = cacheRefreshManager;
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java Mon May  5 12:43:01 2008
@@ -46,7 +46,7 @@
         CacheKey cacheKey = this.constructCacheKey();
         // checked for a cached value first
         CacheValue cachedValue = this.getCachedValue(cacheKey);
-        if (cachedValue != null) {
+        if (cachedValue != null && cachedValue.isValid(cacheKey)) {
             // cached value found
             cachedValue.writeTo(outputStream);
             return;
@@ -56,16 +56,14 @@
         this.invokeStarter();
 
         // cache the result
-        if (cacheKey != null) {
-            this.pipelineCache.put(cacheKey, new CompleteCacheValue(cachingOutputStream.getContent()));
-        }
+        this.setCachedValue(cacheKey, new CompleteCacheValue(cachingOutputStream.getContent(), cacheKey));
     }
 
     public void setPipelineCache(PipelineCache pipelineCache) {
         this.pipelineCache = pipelineCache;
     }
 
-    private CacheKey constructCacheKey() {
+    protected CacheKey constructCacheKey() {
         CompoundCacheKey result = new CompoundCacheKey();
 
         for (PipelineComponent pipelineComponent : this.getComponents()) {
@@ -83,11 +81,17 @@
         return result;
     }
 
-    private CacheValue getCachedValue(CacheKey cacheKey) {
+    protected CacheValue getCachedValue(CacheKey cacheKey) {
         if (cacheKey == null) {
             return null;
         }
 
         return this.pipelineCache.get(cacheKey);
     }
+
+    protected void setCachedValue(CacheKey cacheKey, CacheValue cacheValue) {
+        if (cacheKey != null) {
+            this.pipelineCache.put(cacheKey, cacheValue);
+        }
+    }
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java Mon May  5 12:43:01 2008
@@ -20,4 +20,5 @@
 
 public interface CacheKey {
 
+    boolean isValid(CacheKey cacheKey);
 }

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java?rev=653569&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java Mon May  5 12:43:01 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.corona.pipeline.caching;
+
+
+public interface CacheRefreshJob {
+
+    void refresh(CacheKey cacheKey);
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshJob.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java?rev=653569&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java Mon May  5 12:43:01 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.corona.pipeline.caching;
+
+
+public interface CacheRefreshManager {
+
+    void refreshCacheValue(CacheKey cacheKey, CacheRefreshJob cacheRefreshJob);
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java?rev=653569&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java Mon May  5 12:43:01 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.corona.pipeline.caching;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class CacheRefreshManagerImpl implements CacheRefreshManager {
+
+    private ExecutorService executorService = Executors.newFixedThreadPool(50);
+    private List<CacheKey> pendingCacheKeys = Collections.synchronizedList(new LinkedList<CacheKey>());
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.caching.CacheRefreshManager#refreshCacheValue(org.apache.cocoon.corona.pipeline.caching.CacheKey,
+     *      org.apache.cocoon.corona.pipeline.caching.CacheRefreshJob)
+     */
+    public void refreshCacheValue(CacheKey cacheKey, CacheRefreshJob cacheRefreshJob) {
+        if (this.pendingCacheKeys.contains(cacheKey)) {
+            // the refresh of this cache key is already scheduled
+            return;
+        }
+
+        this.pendingCacheKeys.add(cacheKey);
+        this.executorService.execute(new RefreshWorker(cacheKey, cacheRefreshJob));
+    }
+
+    protected void executeCacheRefreshJob(CacheRefreshJob cacheRefreshJob, CacheKey cacheKey) {
+        cacheRefreshJob.refresh(cacheKey);
+        this.pendingCacheKeys.remove(cacheKey);
+    }
+
+    private class RefreshWorker implements Runnable {
+
+        private final CacheKey cacheKey;
+        private final CacheRefreshJob cacheRefreshJob;
+
+        public RefreshWorker(CacheKey cacheKey, CacheRefreshJob cacheRefreshJob) {
+            this.cacheKey = cacheKey;
+            this.cacheRefreshJob = cacheRefreshJob;
+        }
+
+        public void run() {
+            CacheRefreshManagerImpl.this.executeCacheRefreshJob(this.cacheRefreshJob, this.cacheKey);
+        }
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheRefreshManagerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheValue.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheValue.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheValue.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheValue.java Mon May  5 12:43:01 2008
@@ -23,6 +23,7 @@
 
 public interface CacheValue {
 
-    void writeTo(OutputStream outputStream) throws IOException;
+    boolean isValid(CacheKey cacheKey);
 
+    void writeTo(OutputStream outputStream) throws IOException;
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompleteCacheValue.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompleteCacheValue.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompleteCacheValue.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompleteCacheValue.java Mon May  5 12:43:01 2008
@@ -24,11 +24,22 @@
 public class CompleteCacheValue implements CacheValue {
 
     private final byte[] content;
+    private final CacheKey cacheKey;
 
-    public CompleteCacheValue(byte[] content) {
+    public CompleteCacheValue(byte[] content, CacheKey cacheKey) {
         super();
 
         this.content = content;
+        this.cacheKey = cacheKey;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.caching.CacheValue#isValid(org.apache.cocoon.corona.pipeline.caching.CacheKey)
+     */
+    public boolean isValid(CacheKey cacheKey) {
+        return this.cacheKey != null && this.cacheKey.isValid(cacheKey);
     }
 
     /**

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java Mon May  5 12:43:01 2008
@@ -66,4 +66,30 @@
 
         return result;
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.caching.CacheKey#isValid(org.apache.cocoon.corona.pipeline.caching.CacheKey)
+     */
+    public boolean isValid(CacheKey cacheKey) {
+        if (!this.equals(cacheKey)) {
+            return false;
+        }
+
+        CompoundCacheKey other = (CompoundCacheKey) cacheKey;
+        Iterator<CacheKey> myIterator = this.cacheKeys.iterator();
+        Iterator<CacheKey> otherIterator = other.cacheKeys.iterator();
+
+        while (myIterator.hasNext()) {
+            CacheKey myCacheKey = myIterator.next();
+            CacheKey otherCacheKey = otherIterator.next();
+
+            if (!myCacheKey.isValid(otherCacheKey)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java Mon May  5 12:43:01 2008
@@ -29,4 +29,8 @@
     public int hashCode() {
         return this.getClass().hashCode();
     }
+
+    public boolean isValid(CacheKey cacheKey) {
+        return true;
+    }
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java Mon May  5 12:43:01 2008
@@ -32,10 +32,6 @@
         this.timestamp = timestamp;
     }
 
-    public long getTimestamp() {
-        return this.timestamp;
-    }
-
     @Override
     public boolean equals(Object obj) {
         if (!(obj instanceof TimestampCacheKey)) {
@@ -43,11 +39,24 @@
         }
 
         TimestampCacheKey other = (TimestampCacheKey) obj;
-        return this.timestamp == other.timestamp && this.url.equals(other.url);
+        return this.url.equals(other.url);
+    }
+
+    public long getTimestamp() {
+        return this.timestamp;
     }
 
     @Override
     public int hashCode() {
-        return (int) (this.timestamp ^ this.timestamp >>> 32);
+        return this.url.hashCode();
+    }
+
+    public boolean isValid(CacheKey cacheKey) {
+        if (!this.equals(cacheKey)) {
+            return false;
+        }
+
+        TimestampCacheKey other = (TimestampCacheKey) cacheKey;
+        return this.timestamp == other.timestamp;
     }
 }

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline.xml?rev=653569&r1=653568&r2=653569&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline.xml (original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline.xml Mon May  5 12:43:01 2008
@@ -24,11 +24,21 @@
   <bean name="org.apache.cocoon.corona.sitemap.spring.PipelineFactory" class="org.apache.cocoon.corona.sitemap.spring.PrototypePipelineFactory" />
 
   <bean name="pipeline:caching" class="org.apache.cocoon.corona.pipeline.CachingPipeline" scope="prototype">
-    <property name="pipelineCache" ref="pipelineCache" />
+    <property name="pipelineCache" ref="org.apache.cocoon.corona.pipeline.caching.PipelineCache" />
   </bean>
+  <alias name="pipeline:caching" alias="pipeline:sync-caching" />
 
   <bean name="pipeline:noncaching" class="org.apache.cocoon.corona.pipeline.NonCachingPipeline" scope="prototype" />
 
-  <bean name="pipelineCache" class="org.apache.cocoon.corona.pipeline.caching.SimplePipelineCache" />
+  <bean name="pipeline:async-caching" class="org.apache.cocoon.corona.pipeline.AsyncCachePipeline" scope="prototype">
+    <property name="cacheRefreshManager" ref="org.apache.cocoon.corona.pipeline.caching.CacheRefreshManager" />
+    <property name="pipelineCache" ref="org.apache.cocoon.corona.pipeline.caching.PipelineCache" />
+  </bean>
+
+  <bean name="org.apache.cocoon.corona.pipeline.caching.PipelineCache" class="org.apache.cocoon.corona.pipeline.caching.SimplePipelineCache" />
+
+  <bean name="org.apache.cocoon.corona.pipeline.caching.CacheRefreshManager"
+    class="org.apache.cocoon.corona.pipeline.caching.CacheRefreshManagerImpl">
+  </bean>
 
 </beans>