Skip to content

Commit 275e3c4

Browse files
committed
Added readme docs
1 parent 09962db commit 275e3c4

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
# ipdata-java-client
22
![Build Status](https://www.travis-ci.org/yassine/ipdata-java-client.svg?branch=master)
3-
[![Coverage Status](https://sonarcloud.io/api/project_badges/measure?metric=coverage&project=com.github.yassine%3Aipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
4-
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?metric=alert_status&project=com.github.yassine%3Aipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
5-
[![Maintainability](https://sonarcloud.io/api/project_badges/measure?metric=sqale_rating&project=com.github.yassine%3Aipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
6-
[![Reliability](https://sonarcloud.io/api/project_badges/measure?metric=reliability_rating&project=com.github.yassine%3Aipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
3+
[![Coverage Status](https://sonarcloud.io/api/project_badges/measure?metric=coverage&project=yassine_ipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
4+
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?metric=alert_status&project=yassine_ipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
5+
[![Maintainability](https://sonarcloud.io/api/project_badges/measure?metric=sqale_rating&project=yassine_ipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
6+
[![Reliability](https://sonarcloud.io/api/project_badges/measure?metric=reliability_rating&project=yassine_ipdata-java-client)](https://sonarcloud.io/dashboard/index/com.github.yassine:ipdata-java-client)
7+
78

89
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+

src/main/java/io/ipdata/client/Ipdata.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public static class Builder {
5151
@Setter
5252
private Client feignClient;
5353

54+
/**
55+
* Overrides current cache config with null (no caching).
56+
* @return this
57+
*/
58+
public Builder noCache(){
59+
this .cacheConfig = null;
60+
return this;
61+
}
62+
5463
/**
5564
* Configures a cache with default configuration parameters.
5665
* Note: Overrides any previously configured cache.

0 commit comments

Comments
 (0)