Skip to content

Commit

Permalink
Issue ipinfo#51 Simple Cache is not Thread Safe (and remove unused im…
Browse files Browse the repository at this point in the history
…ports)
  • Loading branch information
Thierry De Leeuw committed Sep 11, 2024
1 parent 32b6aac commit eb893b5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/main/java/io/ipinfo/api/cache/Cache.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.ipinfo.api.cache;

import io.ipinfo.api.model.ASNResponse;
import io.ipinfo.api.model.IPResponse;

public interface Cache {
/**
* Gets an arbitrary object stored in cache.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ipinfo/api/cache/SimpleCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoField;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SimpleCache implements Cache {
private final Duration duration;
private final Map<String, Payload> cache = new HashMap<>();
private final Map<String, Payload> cache = new ConcurrentHashMap<>();

public SimpleCache(Duration duration) {
this.duration = duration;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/ipinfo/api/request/MapRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import io.ipinfo.api.errors.ErrorResponseException;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.MapResponse;
import okhttp3.*;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import java.util.List;

Expand Down
3 changes: 0 additions & 3 deletions src/test/java/io/ipinfo/IPinfoTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package io.ipinfo;

import io.ipinfo.api.IPinfo;
import io.ipinfo.api.errors.ErrorResponseException;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.ASNResponse;
import io.ipinfo.api.model.IPResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down

0 comments on commit eb893b5

Please sign in to comment.