Skip to content

Commit

Permalink
fix batch 3
Browse files Browse the repository at this point in the history
  • Loading branch information
wzy1935 committed Aug 8, 2024
1 parent 1d8e3c9 commit 14f25f5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
11 changes: 4 additions & 7 deletions src/main/java/io/vertx/httpproxy/impl/CacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
import io.vertx.httpproxy.spi.cache.Cache;
import io.vertx.httpproxy.spi.cache.Resource;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.*;

/**
* Simplistic implementation.
*/
public class CacheImpl implements Cache {

private final int maxSize;
private final LinkedHashMap<String, Resource> data;
private final Map<String, Resource> data;

public CacheImpl(CacheOptions options) {
this.maxSize = options.getMaxSize();
this.data = new LinkedHashMap<>() {
this.data = Collections.synchronizedMap(new LinkedHashMap<>() {
@Override
protected boolean removeEldestEntry(Map.Entry<String, Resource> eldest) {
return size() > maxSize;
}
};
});
}


Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/vertx/httpproxy/impl/CachingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ private Future<ProxyResponse> tryHandleProxyRequestFromCache(ProxyContext contex
if (etag != null) {
proxyRequest.headers().set(HttpHeaders.IF_NONE_MATCH, resource.getEtag());
context.set("cached_resource", resource);
return context.sendRequest();
} else {
return context.sendRequest();
}
return context.sendRequest();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.time.Instant;

@RunWith(VertxUnitRunner.class)
public abstract class CacheSpiBase {
public abstract class CacheSpiTestBase {

protected Cache cache;
protected CacheOptions cacheOptions;
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/io/vertx/tests/cache/spi/LocalCacheTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package io.vertx.tests.cache.spi;

import io.vertx.core.http.HttpClientOptions;
import io.vertx.ext.unit.TestContext;
import io.vertx.httpproxy.cache.CacheOptions;
import io.vertx.httpproxy.impl.CacheImpl;

public class LocalCacheTest extends CacheSpiBase {
public class LocalCacheTest extends CacheSpiTestBase {

@Override
public void setUp() {
Expand Down

0 comments on commit 14f25f5

Please sign in to comment.