hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1044826 - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/BasicHttpCache.java test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
Date Sun, 12 Dec 2010 14:37:49 GMT
Author: jonm
Date: Sun Dec 12 14:37:48 2010
New Revision: 1044826

URL: http://svn.apache.org/viewvc?rev=1044826&view=rev
Log:
HTTPCLIENT-1032: variant storage now separates a "variant key" (determined by
the portion of a request covered by Vary headers on an entry) from a
"variant cache key" (the place in the cache storage where a particular variant
response is stored). The variantMap in an HttpCacheEntry now maps variant keys
to variant cache keys, setting us up for the possibility of having multiple
variant keys point to the same variant cache entry.

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java?rev=1044826&r1=1044825&r2=1044826&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
Sun Dec 12 14:37:48 2010
@@ -113,7 +113,9 @@ class BasicHttpCache implements HttpCach
 
             public HttpCacheEntry update(HttpCacheEntry existing) throws IOException {
                 return doGetUpdatedParentEntry(
-                        req.getRequestLine().getUri(), existing, entry, variantURI);
+                        req.getRequestLine().getUri(), existing, entry,
+                        uriExtractor.getVariantKey(req, entry),
+                        variantURI);
             }
 
         };
@@ -162,14 +164,15 @@ class BasicHttpCache implements HttpCach
             final String requestId,
             final HttpCacheEntry existing,
             final HttpCacheEntry entry,
-            final String variantURI) throws IOException {
+            final String variantKey,
+            final String variantCacheKey) throws IOException {
         HttpCacheEntry src = existing;
         if (src == null) {
             src = entry;
         }
         
         Map<String,String> variantMap = new HashMap<String,String>(src.getVariantMap());
-        variantMap.put(variantURI, variantURI);
+        variantMap.put(variantKey, variantCacheKey);
         Resource resource = resourceFactory.copy(requestId, src.getResource());
         return new HttpCacheEntry(
                 src.getRequestDate(),
@@ -228,8 +231,9 @@ class BasicHttpCache implements HttpCach
         HttpCacheEntry root = storage.getEntry(uriExtractor.getURI(host, request));
         if (root == null) return null;
         if (!root.hasVariants()) return root;
-        HttpCacheEntry variant = storage.getEntry(uriExtractor.getVariantURI(host, request,
root));
-        return variant;
+        String variantCacheKey = root.getVariantMap().get(uriExtractor.getVariantKey(request,
root));
+        if (variantCacheKey == null) return null;
+        return storage.getEntry(variantCacheKey);
     }
 
     public void flushInvalidatedCacheEntriesFor(HttpHost host,

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java?rev=1044826&r1=1044825&r2=1044826&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestBasicHttpCache.java
Sun Dec 12 14:37:48 2010
@@ -196,18 +196,21 @@ public class TestBasicHttpCache {
 
     @Test
     public void testCacheUpdateAddsVariantURIToParentEntry() throws Exception {
-        final String parentKey = "parentKey";
-        final String variantKey = "variantKey";
+        final String parentCacheKey = "parentCacheKey";
+        final String variantCacheKey = "variantCacheKey";
         final String existingVariantKey = "existingVariantKey";
+        final String newVariantCacheKey = "newVariantCacheKey";
+        final String newVariantKey = "newVariantKey";
         final Map<String,String> existingVariants = new HashMap<String,String>();
-        existingVariants.put(existingVariantKey,existingVariantKey);
+        existingVariants.put(existingVariantKey, variantCacheKey);
         final HttpCacheEntry parent = HttpTestUtils.makeCacheEntry(existingVariants);
         final HttpCacheEntry variant = HttpTestUtils.makeCacheEntry();
 
-        HttpCacheEntry result = impl.doGetUpdatedParentEntry(parentKey, parent, variant,
variantKey);
-        assertEquals(2, result.getVariantMap().size());
-        assertTrue(result.getVariantMap().containsKey(existingVariantKey));
-        assertTrue(result.getVariantMap().containsKey(variantKey));
+        HttpCacheEntry result = impl.doGetUpdatedParentEntry(parentCacheKey, parent, variant,
newVariantKey, newVariantCacheKey);
+        Map<String,String> resultMap = result.getVariantMap();
+        assertEquals(2, resultMap.size());
+        assertEquals(variantCacheKey, resultMap.get(existingVariantKey));
+        assertEquals(newVariantCacheKey, resultMap.get(newVariantKey));
     }
 
     @Test



Mime
View raw message