abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r429453 - in /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol: cache/Cache.java cache/CacheBase.java client/CommonsClient.java util/CacheControlUtil.java
Date Mon, 07 Aug 2006 20:00:30 GMT
Author: jmsnell
Date: Mon Aug  7 13:00:30 2006
New Revision: 429453

URL: http://svn.apache.org/viewvc?rev=429453&view=rev
Log:
It's a bit inefficient, but let's clear an entry from the cache for every non-idempotent method.
 There's a better way to do this,
but for now, this works.

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/Cache.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/Cache.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/Cache.java?rev=429453&r1=429452&r2=429453&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/Cache.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/Cache.java
Mon Aug  7 13:00:30 2006
@@ -51,6 +51,7 @@
     CacheKey key);
   
   Response update(
+    String method,
     String uri, 
     RequestOptions options, 
     Response response);

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java?rev=429453&r1=429452&r2=429453&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java
Mon Aug  7 13:00:30 2006
@@ -21,6 +21,7 @@
 
 import org.apache.abdera.protocol.client.RequestOptions;
 import org.apache.abdera.protocol.client.Response;
+import org.apache.abdera.protocol.util.CacheControlUtil;
 
 public abstract class CacheBase 
   implements Cache {
@@ -118,11 +119,13 @@
   }
   
   public Response update(
+    String method,
     String uri, 
     RequestOptions options,
     Response response) {
     CacheKey key = getCacheKey(uri, options,response);
-    if ((response != null && response.isNoStore())) {
+    if ((response != null && response.isNoStore()) || 
+        !CacheControlUtil.isIdempotent(method)) {
 // TODO: Need to get clarification on this.. if the request is no-store, can
 //       the response be cached.
 //    if ((response != null && response.isNoStore()) ||

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java?rev=429453&r1=429452&r2=429453&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
Mon Aug  7 13:00:30 2006
@@ -24,6 +24,7 @@
 import org.apache.abdera.protocol.cache.Cache;
 import org.apache.abdera.protocol.cache.CacheDisposition;
 import org.apache.abdera.protocol.cache.CachedResponse;
+import org.apache.abdera.protocol.util.CacheControlUtil;
 import org.apache.abdera.protocol.util.ExtensionMethod;
 import org.apache.abdera.util.Version;
 import org.apache.commons.httpclient.Credentials;
@@ -68,16 +69,6 @@
       HttpClientParams.USE_EXPECT_CONTINUE, true);    
   }
   
-  /**
-   * We're only going to cache GET, HEAD and OPTIONS requests.
-   * State modifying requests will be passed on through to the server
-   */
-  private boolean isPassthroughMethod(String method) {
-    return (!method.equals("GET") &&
-            !method.equals("HEAD") &&
-            !method.equals("OPTIONS"));
-  }
-  
   @Override
   public Response execute(
     String method, 
@@ -90,7 +81,7 @@
         CachedResponse cached_response = null;
         Cache cache = getCache();
         CacheDisposition disp = CacheDisposition.TRANSPARENT;
-        if (!isPassthroughMethod(method) &&
+        if (CacheControlUtil.isIdempotent(method) &&
             cache != null && 
             options.getNoCache() == false && 
             options.getNoStore() == false &&
@@ -136,7 +127,7 @@
             response = new CommonsResponse(httpMethod);
             if (cache != null) 
               response = cache.update(
-                uri, options, response);
+                method, uri, options, response);
           }
         }
         return response;

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java?rev=429453&r1=429452&r2=429453&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java
Mon Aug  7 13:00:30 2006
@@ -22,6 +22,12 @@
 
 public class CacheControlUtil {
 
+  public static boolean isIdempotent(String method) {
+    return (method.equalsIgnoreCase("GET") ||
+            method.equalsIgnoreCase("HEAD") ||
+            method.equalsIgnoreCase("OPTIONS"));
+  }
+  
   private static long value(String val) {
     return (val != null) ? Long.parseLong(val) : -1; 
   }



Mime
View raw message