Renamed URIExtractor to CacheKeyGenerator, which is more descriptive
of what we actually use it for. git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1049278 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7bb8ecbf98
commit
d60c36c40c
|
@ -50,7 +50,7 @@ import org.apache.http.message.BasicHttpResponse;
|
|||
|
||||
class BasicHttpCache implements HttpCache {
|
||||
|
||||
private final URIExtractor uriExtractor;
|
||||
private final CacheKeyGenerator uriExtractor;
|
||||
private final ResourceFactory resourceFactory;
|
||||
private final int maxObjectSizeBytes;
|
||||
private final CacheEntryUpdater cacheEntryUpdater;
|
||||
|
@ -62,7 +62,7 @@ class BasicHttpCache implements HttpCache {
|
|||
|
||||
public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config) {
|
||||
this.resourceFactory = resourceFactory;
|
||||
this.uriExtractor = new URIExtractor();
|
||||
this.uriExtractor = new CacheKeyGenerator();
|
||||
this.cacheEntryUpdater = new CacheEntryUpdater(resourceFactory);
|
||||
this.maxObjectSizeBytes = config.getMaxObjectSizeBytes();
|
||||
this.responseGenerator = new CachedHttpResponseGenerator();
|
||||
|
|
|
@ -50,19 +50,19 @@ import org.apache.http.client.cache.HttpCacheStorage;
|
|||
class CacheInvalidator {
|
||||
|
||||
private final HttpCacheStorage storage;
|
||||
private final URIExtractor uriExtractor;
|
||||
private final CacheKeyGenerator uriExtractor;
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
/**
|
||||
* Create a new {@link CacheInvalidator} for a given {@link HttpCache} and
|
||||
* {@link URIExtractor}.
|
||||
* {@link CacheKeyGenerator}.
|
||||
*
|
||||
* @param uriExtractor Provides identifiers for the keys to store cache entries
|
||||
* @param storage the cache to store items away in
|
||||
*/
|
||||
public CacheInvalidator(
|
||||
final URIExtractor uriExtractor,
|
||||
final CacheKeyGenerator uriExtractor,
|
||||
final HttpCacheStorage storage) {
|
||||
this.uriExtractor = uriExtractor;
|
||||
this.storage = storage;
|
||||
|
|
|
@ -50,7 +50,7 @@ import org.apache.http.protocol.HTTP;
|
|||
* @since 4.1
|
||||
*/
|
||||
@Immutable
|
||||
class URIExtractor {
|
||||
class CacheKeyGenerator {
|
||||
|
||||
/**
|
||||
* For a given {@link HttpHost} and {@link HttpRequest} get a URI from the
|
|
@ -70,7 +70,7 @@ public class TestBasicHttpCache {
|
|||
public void testCanFlushCacheEntriesAtUri() throws Exception {
|
||||
HttpHost host = new HttpHost("foo.example.com");
|
||||
HttpRequest req = new HttpDelete("/bar");
|
||||
final String key = (new URIExtractor()).getURI(host, req);
|
||||
final String key = (new CacheKeyGenerator()).getURI(host, req);
|
||||
HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
||||
|
||||
backing.map.put(key, entry);
|
||||
|
@ -217,7 +217,7 @@ public class TestBasicHttpCache {
|
|||
assertFalse(entry.hasVariants());
|
||||
HttpHost host = new HttpHost("foo.example.com");
|
||||
HttpRequest req = new HttpGet("http://foo.example.com/bar");
|
||||
String key = (new URIExtractor()).getURI(host, req);
|
||||
String key = (new CacheKeyGenerator()).getURI(host, req);
|
||||
|
||||
impl.storeInCache(host, req, entry);
|
||||
assertSame(entry, backing.map.get(key));
|
||||
|
@ -263,7 +263,7 @@ public class TestBasicHttpCache {
|
|||
|
||||
HttpResponse result = impl.cacheAndReturnResponse(host, request, originResponse, requestSent, responseReceived);
|
||||
assertEquals(1, backing.map.size());
|
||||
assertTrue(backing.map.containsKey((new URIExtractor()).getURI(host, request)));
|
||||
assertTrue(backing.map.containsKey((new CacheKeyGenerator()).getURI(host, request)));
|
||||
assertTrue(HttpTestUtils.semanticallyTransparent(originResponse, result));
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ public class TestBasicHttpCache {
|
|||
HttpHost host = new HttpHost("foo.example.com");
|
||||
HttpRequest request = new HttpGet("http://foo.example.com/bar");
|
||||
|
||||
String key = (new URIExtractor()).getURI(host, request);
|
||||
String key = (new CacheKeyGenerator()).getURI(host, request);
|
||||
|
||||
backing.map.put(key,entry);
|
||||
|
||||
|
|
|
@ -48,14 +48,14 @@ public class TestCacheInvalidator {
|
|||
private CacheInvalidator impl;
|
||||
private HttpCacheStorage mockStorage;
|
||||
private HttpHost host;
|
||||
private URIExtractor extractor;
|
||||
private CacheKeyGenerator extractor;
|
||||
private HttpCacheEntry mockEntry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
host = new HttpHost("foo.example.com");
|
||||
mockStorage = EasyMock.createMock(HttpCacheStorage.class);
|
||||
extractor = new URIExtractor();
|
||||
extractor = new CacheKeyGenerator();
|
||||
mockEntry = EasyMock.createMock(HttpCacheEntry.class);
|
||||
|
||||
impl = new CacheInvalidator(extractor, mockStorage);
|
||||
|
|
|
@ -39,13 +39,13 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestURIExtractor {
|
||||
public class TestCacheKeyGenerator {
|
||||
|
||||
private static final BasicHttpRequest REQUEST_FULL_EPISODES = new BasicHttpRequest("GET",
|
||||
"/full_episodes");
|
||||
private static final BasicHttpRequest REQUEST_ROOT = new BasicHttpRequest("GET", "/");
|
||||
|
||||
URIExtractor extractor;
|
||||
CacheKeyGenerator extractor;
|
||||
private HttpHost host;
|
||||
private HttpCacheEntry mockEntry;
|
||||
private HttpRequest mockRequest;
|
||||
|
@ -55,7 +55,7 @@ public class TestURIExtractor {
|
|||
host = new HttpHost("foo.example.com");
|
||||
mockEntry = EasyMock.createMock(HttpCacheEntry.class);
|
||||
mockRequest = EasyMock.createMock(HttpRequest.class);
|
||||
extractor = new URIExtractor();
|
||||
extractor = new CacheKeyGenerator();
|
||||
}
|
||||
|
||||
private void replayMocks() {
|
||||
|
@ -124,7 +124,7 @@ public class TestURIExtractor {
|
|||
public void testGetVariantURIWithNoVaryHeaderReturnsNormalURI() {
|
||||
final String theURI = "theURI";
|
||||
org.easymock.EasyMock.expect(mockEntry.hasVariants()).andReturn(false);
|
||||
extractor = new URIExtractor() {
|
||||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(HttpHost h, HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
|
@ -145,7 +145,7 @@ public class TestURIExtractor {
|
|||
Header[] varyHeaders = { new BasicHeader("Vary", "Accept-Encoding") };
|
||||
Header[] encHeaders = { new BasicHeader("Accept-Encoding", "gzip") };
|
||||
|
||||
extractor = new URIExtractor() {
|
||||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(HttpHost h, HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
|
@ -170,7 +170,7 @@ public class TestURIExtractor {
|
|||
final String theURI = "theURI";
|
||||
Header[] noHeaders = new Header[0];
|
||||
Header[] varyHeaders = { new BasicHeader("Vary", "Accept-Encoding") };
|
||||
extractor = new URIExtractor() {
|
||||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(HttpHost h, HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
|
@ -196,7 +196,7 @@ public class TestURIExtractor {
|
|||
Header[] varyHeaders = { new BasicHeader("Vary", "User-Agent, Accept-Encoding") };
|
||||
Header[] encHeaders = { new BasicHeader("Accept-Encoding", "gzip") };
|
||||
Header[] uaHeaders = { new BasicHeader("User-Agent", "browser") };
|
||||
extractor = new URIExtractor() {
|
||||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(HttpHost h, HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
|
@ -224,7 +224,7 @@ public class TestURIExtractor {
|
|||
new BasicHeader("Vary", "Accept-Encoding") };
|
||||
Header[] encHeaders = { new BasicHeader("Accept-Encoding", "gzip") };
|
||||
Header[] uaHeaders = { new BasicHeader("User-Agent", "browser") };
|
||||
extractor = new URIExtractor() {
|
||||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(HttpHost h, HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
|
@ -251,7 +251,7 @@ public class TestURIExtractor {
|
|||
Header[] encHeaders = { new BasicHeader("Accept-Encoding", "gzip"),
|
||||
new BasicHeader("Accept-Encoding", "deflate") };
|
||||
Header[] uaHeaders = { new BasicHeader("User-Agent", "browser") };
|
||||
extractor = new URIExtractor() {
|
||||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(HttpHost h, HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
Loading…
Reference in New Issue