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. git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1044826 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4e7d9fa5c8
commit
62dd08891c
|
@ -113,7 +113,9 @@ class BasicHttpCache implements HttpCache {
|
|||
|
||||
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 HttpCache {
|
|||
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 HttpCache {
|
|||
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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue