cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r161301 - cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
Date Thu, 14 Apr 2005 15:17:56 GMT
Author: vgritsenko
Date: Thu Apr 14 08:17:55 2005
New Revision: 161301

URL: http://svn.apache.org/viewcvs?view=rev&rev=161301
Log:
perform validity check in accordance with contract

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java?view=diff&r1=161300&r2=161301
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/DefaultCacheManager.java
Thu Apr 14 08:17:55 2005
@@ -15,8 +15,6 @@
  */
 package org.apache.cocoon.forms;
 
-import java.io.IOException;
-
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.component.Component;
 import org.apache.avalon.framework.configuration.Configurable;
@@ -27,22 +25,31 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
+
 import org.apache.commons.collections.FastHashMap;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceValidity;
 
+import java.io.IOException;
+import java.util.Map;
+
 /**
  * Component implementing the {@link CacheManager} role.
  *
  * @version $Id$
  */
 public class DefaultCacheManager
-  extends AbstractLogEnabled
-  implements CacheManager, ThreadSafe, Serviceable, Disposable, Configurable, Component {
+        extends AbstractLogEnabled
+        implements CacheManager, ThreadSafe, Serviceable, Disposable,
+                   Configurable, Component {
 
     protected ServiceManager manager;
     protected Configuration configuration;
-    protected FastHashMap cache = new FastHashMap();
+    protected Map cache;
+
+    public DefaultCacheManager() {
+        this.cache = new FastHashMap();
+    }
 
     public void service(ServiceManager serviceManager) throws ServiceException {
         this.manager = serviceManager;
@@ -56,34 +63,25 @@
     }
 
     public Object get(Source source, String prefix) {
-        String key = prefix + source.getURI();
-        SourceValidity newValidity = source.getValidity();
-
-        // If source is not valid then remove object from cache and return null
-        if (newValidity == null) {
-            this.cache.remove(key);
-            return null;
-        }
+        // Create a cache key
+        final String key = prefix + source.getURI();
 
-        // If object is not in cache then return null
+        // If object is not in the cache then return null
         Object[] objectAndValidity = (Object[]) this.cache.get(key);
         if (objectAndValidity == null) {
             return null;
         }
 
-        // Check stored validity against current source validity
-        SourceValidity storedValidity = (SourceValidity) objectAndValidity[1];
-        int valid = storedValidity.isValid();
-        boolean isValid;
+        // If object is in the cache, check stored object validity
+        final SourceValidity validity = (SourceValidity) objectAndValidity[1];
+        int valid = validity.isValid();
         if (valid == SourceValidity.UNKNOWN) {
-            valid = storedValidity.isValid(newValidity);
-            isValid = (valid == SourceValidity.VALID);
-        } else {
-            isValid = (valid == SourceValidity.VALID);
+            // Compare against current source validity
+            valid = validity.isValid(source.getValidity());
         }
 
         // If stored object is not valid then remove object from cache and return null
-        if (!isValid) {
+        if (valid != SourceValidity.VALID) {
             this.cache.remove(key);
             return null;
         }
@@ -93,11 +91,11 @@
     }
 
     public void set(Object object, Source source, String prefix) throws IOException {
-        String key = prefix + source.getURI();
-        SourceValidity validity = source.getValidity();
+        final String key = prefix + source.getURI();
+        final SourceValidity validity = source.getValidity();
         if (validity != null) {
             Object[] objectAndValidity = {object,  validity};
-            cache.put(key, objectAndValidity);
+            this.cache.put(key, objectAndValidity);
         }
     }
 



Mime
View raw message