|
1 | 1 | # ipdata-java-client |
2 | 2 |  |
3 | | -[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
4 | | -[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
5 | | -[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
6 | | -[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
| 3 | +[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
| 4 | +[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
| 5 | +[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
| 6 | +[](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client) |
| 7 | + |
7 | 8 |
|
8 | 9 | An <i>ipdata.co</i> java client. |
| 10 | + |
| 11 | +Recipes: |
| 12 | +1. I wanna call the api without caching results : |
| 13 | +```java |
| 14 | +URL url = new URL("https://api.ipdata.co"); |
| 15 | +IpdataService ipdataService = Ipdata.builder().url(url) |
| 16 | + .noCache() |
| 17 | + .key("MY_KEY") |
| 18 | + .get(); |
| 19 | +IpdataModel model = ipdataService.get("1.1.1.1"); |
| 20 | +``` |
| 21 | +2. I wanna call the api while caching results for further calls on the same IP (caching will yield you a latency of less than 1ms for requests that hit the cache): |
| 22 | +```java |
| 23 | +URL url = new URL("https://api.ipdata.co"); |
| 24 | +IpdataService ipdataService = Ipdata.builder().url(url) |
| 25 | + .withDefaultCache() |
| 26 | + .key("MY_KEY").get(); |
| 27 | +IpdataModel model = ipdataService.get("1.1.1.1"); //cache miss here |
| 28 | +ipdataService.get("1.1.1.1"); //cache hit from here on ip address "1.1.1.1" |
| 29 | +``` |
| 30 | + |
| 31 | +3. My 50% user session length is 30 minutes, and I don't want to have more than 8 * 1024 items in cache, |
| 32 | +how can I do that? |
| 33 | + |
| 34 | +```java |
| 35 | +URL url = new URL("https://api.ipdata.co"); |
| 36 | +IpdataService ipdataService = Ipdata.builder().url(url) |
| 37 | + .withCache() |
| 38 | + .timeout(30, TimeUnit.MINUTES) |
| 39 | + .maxSize(8 * 1024) |
| 40 | + .registerCacheConfig() |
| 41 | + .key("MY_KEY") |
| 42 | + .get(); |
| 43 | +IpdataModel model = ipdataService.get("1.1.1.1"); //cache miss here |
| 44 | +ipdataService.get("1.1.1.1"); //cache hit from here on ip address "1.1.1.1" |
| 45 | +``` |
| 46 | + |
| 47 | + |
0 commit comments