Skip to content

Commit 14f25f5

Browse files
committed
fix batch 3
1 parent 1d8e3c9 commit 14f25f5

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

src/main/java/io/vertx/httpproxy/impl/CacheImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66
import io.vertx.httpproxy.spi.cache.Cache;
77
import io.vertx.httpproxy.spi.cache.Resource;
88

9-
import java.util.HashMap;
10-
import java.util.LinkedHashMap;
11-
import java.util.LinkedList;
12-
import java.util.Map;
9+
import java.util.*;
1310

1411
/**
1512
* Simplistic implementation.
1613
*/
1714
public class CacheImpl implements Cache {
1815

1916
private final int maxSize;
20-
private final LinkedHashMap<String, Resource> data;
17+
private final Map<String, Resource> data;
2118

2219
public CacheImpl(CacheOptions options) {
2320
this.maxSize = options.getMaxSize();
24-
this.data = new LinkedHashMap<>() {
21+
this.data = Collections.synchronizedMap(new LinkedHashMap<>() {
2522
@Override
2623
protected boolean removeEldestEntry(Map.Entry<String, Resource> eldest) {
2724
return size() > maxSize;
2825
}
29-
};
26+
});
3027
}
3128

3229

src/main/java/io/vertx/httpproxy/impl/CachingFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ private Future<ProxyResponse> tryHandleProxyRequestFromCache(ProxyContext contex
122122
if (etag != null) {
123123
proxyRequest.headers().set(HttpHeaders.IF_NONE_MATCH, resource.getEtag());
124124
context.set("cached_resource", resource);
125-
return context.sendRequest();
126-
} else {
127-
return context.sendRequest();
128125
}
126+
return context.sendRequest();
129127
}
130128
}
131129
}

src/test/java/io/vertx/tests/cache/spi/CacheSpiBase.java renamed to src/test/java/io/vertx/tests/cache/spi/CacheSpiTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.time.Instant;
1717

1818
@RunWith(VertxUnitRunner.class)
19-
public abstract class CacheSpiBase {
19+
public abstract class CacheSpiTestBase {
2020

2121
protected Cache cache;
2222
protected CacheOptions cacheOptions;

src/test/java/io/vertx/tests/cache/spi/LocalCacheTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package io.vertx.tests.cache.spi;
22

3-
import io.vertx.core.http.HttpClientOptions;
4-
import io.vertx.ext.unit.TestContext;
5-
import io.vertx.httpproxy.cache.CacheOptions;
63
import io.vertx.httpproxy.impl.CacheImpl;
74

8-
public class LocalCacheTest extends CacheSpiBase {
5+
public class LocalCacheTest extends CacheSpiTestBase {
96

107
@Override
118
public void setUp() {

0 commit comments

Comments
 (0)