cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r162006 - cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java
Date Wed, 20 Apr 2005 03:06:21 GMT
Author: vgritsenko
Date: Tue Apr 19 20:06:20 2005
New Revision: 162006

URL: http://svn.apache.org/viewcvs?view=rev&rev=162006
Log:
implement 'cache-expressions' configuration parameter promised in the javadoc.
sync javadoc with code.

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java?view=diff&r1=162005&r2=162006
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java Tue
Apr 19 20:06:20 2005
@@ -67,18 +67,18 @@
  * Sources can be held in memory for better performance and reloaded if
  * changed.
  *
- * <p>Caching and reloading can be turned on / off (default: on)
- * through <code>&lt;reloadable&gt;false&lt;/reloadable&gt;</code>
and
- * <code>&lt;cacheable&gt;false&lt;/cacheable&gt;</code>. The
file
+ * <p>Caching and reloading can be turned on / off (default: caching on,
+ * reloading off) through <code>&lt;reloadable&gt;false&lt;/reloadable&gt;</code>
+ * and <code>&lt;cacheable&gt;false&lt;/cacheable&gt;</code>.
The file
  * (source) to use is specified through <code>&lt;file
  * src="protocol:path/to/file.xml" reloadable="true"
  * cacheable="true"/&gt;</code> optionally overriding defaults for
- * caching and or reloading.</p>
+ * caching and/or reloading.</p>
  *
  * <p>In addition, xpath expressions are cached for higher performance.
  * Thus, if an expression has been evaluated for a file, the result
  * is cached and will be reused, the expression is not evaluated
- * a second time. This can be turned off using the <code>cache-xpaths</code>
+ * a second time. This can be turned off using the <code>cache-expressions</code>
  * configuration option.</p>
  *
  * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
@@ -97,11 +97,11 @@
     /** Default value for reloadability of sources. Defaults to false. */
     boolean reloadAll;
 
-    /** Default value for cachability of sources. Defaults to true. */
+    /** Default value for cacheability of sources. Defaults to true. */
     boolean cacheAll;
 
-    /** Default value for cachability of xpath expressions. Defaults to true. */
-    boolean cacheExpressions = true;
+    /** Default value for cacheability of xpath expressions. Defaults to true. */
+    boolean cacheExpressions;
 
     /** Default src */
     String src;
@@ -238,33 +238,18 @@
     }
 
     /**
-     * Dispose this component
-     */
-    public void dispose() {
-        super.dispose();
-        if (this.manager != null) {
-            this.manager.release(this.resolver);
-            this.resolver = null;
-            this.manager = null;
-        }
-
-        this.documents = null;
-        this.expressionCache = null;
-        this.expressionValuesCache = null;
-    }
-
-    /**
      * Static (cocoon.xconf) configuration.
      * Configuration is expected to be of the form:
-     * &lt;...>
-     *   &lt;reloadable>true|<b>false</b>&lt;/reloadable>
-     *   &lt;cacheable><b>true</b>|false&lt;/cacheable>
-     *   &lt;file src="<i>src1</i>" reloadable="true|<b>false</b>"
cacheable="<b>true</b>|false"/>
-     *   &lt;file src="<i>src2</i>" reloadable="true|<b>false</b>"
cacheable="<b>true</b>|false"/>
+     * &lt;...&gt;
+     *   &lt;reloadable&gt;true|<b>false</b>&lt;/reloadable&gt;
+     *   &lt;cacheable&gt;<b>true</b>|false&lt;/cacheable&gt;
+     *   &lt;file src="<i>src1</i>" reloadable="true|<b>false</b>"
cacheable="<b>true</b>|false"/&gt;
+     *   &lt;file src="<i>src2</i>" reloadable="true|<b>false</b>"
cacheable="<b>true</b>|false"/&gt;
      *   ...
-     * &lt;/...>
-     * Each &lt;file> pre-loads an XML DOM for querying. Typically only one
-     * &lt;file> is specified, and its <i>src</i> is used as a default
if not
+     * &lt;/...&gt;
+     *
+     * Each &lt;file/&gt; element pre-loads an XML DOM for querying. Typically only
one
+     * &lt;file&gt; is specified, and its <i>src</i> is used as a default
if not
      * overridden in the {@link #getContextObject(Configuration, Map)}
      *
      * @param config a <code>Configuration</code> value, as described above.
@@ -284,7 +269,6 @@
         this.cacheAll = config.getChild("cacheable").getValueAsBoolean(true);
 
         this.documents = Collections.synchronizedMap(new HashMap());
-
         Configuration[] files = config.getChildren("file");
         for (int i = 0; i < files.length; i++) {
             boolean reload = files[i].getAttributeAsBoolean("reloadable", this.reloadAll);
@@ -297,11 +281,31 @@
         }
 
         // init caches
-        this.expressionCache = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT);
-        this.expressionValuesCache = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT);
+        this.cacheExpressions = config.getChild("cache-expressions").getValueAsBoolean(true);
+        if (this.cacheExpressions) {
+            this.expressionCache = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT);
+            this.expressionValuesCache = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT);
+        }
     }
 
     /**
+     * Dispose this component
+     */
+    public void dispose() {
+        super.dispose();
+        if (this.manager != null) {
+            this.manager.release(this.resolver);
+            this.resolver = null;
+            this.manager = null;
+        }
+
+        this.documents = null;
+        this.expressionCache = null;
+        this.expressionValuesCache = null;
+    }
+
+
+    /**
      * Retrieve document helper
      */
     private DocumentHelper getDocumentHelper(Configuration modeConf)
@@ -436,11 +440,13 @@
     }
 
     protected void flushCache() {
-        synchronized(this.expressionCache) {
-            this.expressionCache.clear();
-        }
-        synchronized(this.expressionValuesCache) {
-            this.expressionValuesCache.clear();
+        if (this.cacheExpressions) {
+            synchronized(this.expressionCache) {
+                this.expressionCache.clear();
+            }
+            synchronized(this.expressionValuesCache) {
+                this.expressionValuesCache.clear();
+            }
         }
     }
 



Mime
View raw message