Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sample/Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class Benchmark {
public static void main(String[] args) throws IOException, InvalidDatabaseException {
File file = new File(args.length > 0 ? args[0] : "GeoLite2-City.mmdb");
System.out.println("No caching");
loop("Warming up", file, WARMUPS, new NoCache());
loop("Benchmarking", file, BENCHMARKS, new NoCache());
loop("Warming up", file, WARMUPS, NoCache.getInstance());
loop("Benchmarking", file, BENCHMARKS, NoCache.getInstance());

System.out.println("With caching");
loop("Warming up", file, WARMUPS, new CHMCache());
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/maxmind/db/NoCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
import com.fasterxml.jackson.databind.JsonNode;

/**
* A no-op cache.
* A no-op cache singleton.
*/
public class NoCache implements NodeCache {

private static final NoCache INSTANCE = new NoCache();

private NoCache() {
}

@Override
public JsonNode get(int key, Loader loader) throws IOException {
return loader.load(key);
}

public static NoCache getInstance() {
return INSTANCE;
}

}
8 changes: 3 additions & 5 deletions src/main/java/com/maxmind/db/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public final class Reader implements Closeable {
(byte) 0xCD, (byte) 0xEF, 'M', 'a', 'x', 'M', 'i', 'n', 'd', '.',
'c', 'o', 'm'};

private static final NodeCache NO_CACHE = new NoCache();

private final int ipV4Start;
private final Metadata metadata;
private final AtomicReference<BufferHolder> bufferHolderReference;
Expand Down Expand Up @@ -52,7 +50,7 @@ public enum FileMode {
* @throws IOException if there is an error opening or reading from the file.
*/
public Reader(File database) throws IOException {
this(database, NO_CACHE);
this(database, NoCache.getInstance());
}

/**
Expand All @@ -76,7 +74,7 @@ public Reader(File database, NodeCache cache) throws IOException {
* @throws IOException if there is an error reading from the Stream.
*/
public Reader(InputStream source) throws IOException {
this(source, NO_CACHE);
this(source, NoCache.getInstance());
}

/**
Expand All @@ -101,7 +99,7 @@ public Reader(InputStream source, NodeCache cache) throws IOException {
* @throws IOException if there is an error opening or reading from the file.
*/
public Reader(File database, FileMode fileMode) throws IOException {
this(database, fileMode, NO_CACHE);
this(database, fileMode, NoCache.getInstance());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/maxmind/db/PointerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class PointerTest {
public void testWithPointers() throws IOException {
File file = ReaderTest.getFile("maps-with-pointers.raw");
BufferHolder ptf = new BufferHolder(file, FileMode.MEMORY);
Decoder decoder = new Decoder(new NoCache(), ptf.get(), 0);
Decoder decoder = new Decoder(NoCache.getInstance(), ptf.get(), 0);

ObjectMapper om = new ObjectMapper();

Expand Down