cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r232777 - in /cocoon/branches/BRANCH_2_1_X/src: blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java documentation/xdocs/developing/portal/coplets.xml
Date Mon, 15 Aug 2005 09:08:41 GMT
Author: cziegeler
Date: Mon Aug 15 02:08:33 2005
New Revision: 232777

URL: http://svn.apache.org/viewcvs?rev=232777&view=rev
Log:
Ingore sizing events

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
    cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/developing/portal/coplets.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java?rev=232777&r1=232776&r2=232777&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/CachingURICopletAdapter.java
Mon Aug 15 02:08:33 2005
@@ -27,6 +27,7 @@
 import org.apache.cocoon.portal.PortalService;
 import org.apache.cocoon.portal.coplet.CopletInstanceData;
 import org.apache.cocoon.portal.event.CopletInstanceEvent;
+import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent;
 import org.apache.cocoon.util.Deprecation;
 import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.ContentHandler;
@@ -41,14 +42,23 @@
  * the user session.
  *
  * @author <a href="mailto:gerald.kahrer@rizit.at">Gerald Kahrer</a>
- *
+ * @author <a href="mailto:cziegeler.at.apache.dot.org">Carsten Ziegeler</a>
  * @version $Id$
  */
 public class CachingURICopletAdapter
     extends URICopletAdapter
     implements Parameterizable {
 
-    /** The attribute name for the storing the cached coplet content. */
+    /** The configuration name for enabling/disabling the cache. */
+    public static final String CONFIGURATION_ENABLE_CACHING = "cache-enabled";
+
+    /** The configuration name for using the global cache. */
+    public static final String CONFIGURATION_CACHE_GLOBAL= "cache-global";
+
+    /** The configuration name for ignoring sizing events to clear the cache. */
+    public static final String CONFIGURATION_IGNORE_SIZING_EVENTS = "ignore-sizing-events";
+
+    /** The attribute name for storing the cached coplet content. */
     public static final String CACHE = "cacheData";
 
     /** This attribute can be set on the instance to not cache the current response. */
@@ -119,9 +129,9 @@
                                final ContentHandler contentHandler)
     throws SAXException {
         // Is caching enabled?
-        boolean cachingEnabled = ((Boolean)this.getConfiguration(coplet, "cache-enabled",
this.enableCaching)).booleanValue();
+        boolean cachingEnabled = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_ENABLE_CACHING,
this.enableCaching)).booleanValue();
         // do we cache globally?
-        boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, "cache-global", Boolean.FALSE)).booleanValue();
+        boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_CACHE_GLOBAL,
Boolean.FALSE)).booleanValue();
 
         Object data = null;
         // If caching is enabed and the cache is still valid, then use the cache
@@ -192,17 +202,33 @@
     public void handleCopletInstanceEvent(CopletInstanceEvent event) {
         final CopletInstanceData coplet = (CopletInstanceData) event.getTarget();
 
-        // do we cache globally?
-        boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, "cache-global", Boolean.FALSE)).booleanValue();
-        if ( cacheGlobal ) {
-            final String key = this.getCacheKey(coplet,
-                                                (String) coplet.getCopletData().getAttribute("uri"));
-            this.cache.remove(key);
-        } else {
-            coplet.removeAttribute(CACHE);
+        // do we ignore SizingEvents
+        boolean ignoreSizing = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_IGNORE_SIZING_EVENTS,
Boolean.TRUE)).booleanValue();
+
+        if ( !ignoreSizing || !isSizingEvent(event)) {
+            // do we cache globally?
+            boolean cacheGlobal = ((Boolean)this.getConfiguration(coplet, CONFIGURATION_CACHE_GLOBAL,
Boolean.FALSE)).booleanValue();
+            if ( cacheGlobal ) {
+                final String key = this.getCacheKey(coplet,
+                                                    (String) coplet.getCopletData().getAttribute("uri"));
+                this.cache.remove(key);
+            } else {
+                coplet.removeAttribute(CACHE);
+            }
         }
     }
 
+    /**
+     * Tests if the event is a sizing event for the coplet.
+     */
+    protected boolean isSizingEvent(CopletInstanceEvent event) {
+        if ( event instanceof ChangeCopletInstanceAspectDataEvent ) {
+            if (((ChangeCopletInstanceAspectDataEvent)event).getAspectName().equals("size"))
{
+                return true;
+            }
+        }
+        return false;
+    }
     /**
      * Build the key for the global cache.
      */

Modified: cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/developing/portal/coplets.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/developing/portal/coplets.xml?rev=232777&r1=232776&r2=232777&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/developing/portal/coplets.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/developing/portal/coplets.xml Mon
Aug 15 02:08:33 2005
@@ -315,6 +315,28 @@
        coplet.setAttribute("doNotCache", "1");
      ...]]>
      </source>
+   <p>
+     By default the caching uri adapter ignores sizing events for clearing the cache. This
+     ensures that minimizing a coplet does not clear the cache. However, if you want to
+     disable the cache on a sizing event you can turn this on in the configuration for
+     a coplet data:
+   </p>
+   <source>
+   <![CDATA[...
+     <coplet-data id="Portal-Demo" name="standard">
+       <title>Introduction</title>
+       <coplet-base-data>CachingURICoplet</coplet-base-data>
+       <attribute>
+         <name>uri</name>
+         <value xsi:type="java:java.lang.String" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">cocoon:/coplets/docs/portal-demo.html</value>
+       </attribute>
+       <attribute>
+         <name>ignore-sizing-events</name>
+         <value xsi:type="java:java.lang.Boolean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">false</value>
+       </attribute>
+     </coplet-data>
+   ...]]>
+   </source>
    <s2 title="Global Caching">
      <p>
        The default caching mechanism caches the contents in the user session. If you



Mime
View raw message