Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nstdio committed Apr 9, 2022
1 parent f269d5d commit aec3906
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ implementation 'io.github.nstdio:http-client-ext:2.1.0'
<version>2.1.0</version>
</dependency>
```
### Features

- [Caching](#Caching), both in memory and disk.
- [Decompression](#Decompression): `gzip, deflate`
- [JSON](#JSON) mappings

### Caching

Expand Down Expand Up @@ -52,17 +57,38 @@ HttpResponse<String> cachedResponse = client.send(request, ofString());
and all available configurations for in memory cache:

```java
Cache cache = Cache.newInMemoryCacheBuilder()
Cache inMemory = Cache.newInMemoryCacheBuilder()
.maxItems(4096) // number of responses can be cached
.size(10 * 1000 * 1000) // maximum size of the entire cache in bytes, -1 for no constraint
.requestFilter(request -> request.uri().getHost().equals("api.github.com")) // cache only requests that match given predicate
.responseFilter(response -> response.statusCode() == 200) // cache only responses that match given predicate
.build();
```

the exact same configuration applies to persistent builder with addition of [DiskCacheBuilder#dir](https://github.com/nstdio/http-client-ext/blob/main/src/main/java/io/github/nstdio/http/ext/Cache.java#L163)
Above-mentioned configurations also applies to persistent cache with some additions

```
Path cacheDir = ...
Cache disk = Cache.newDiskCacheBuilder()
.dir(cacheDir)
.build();
```
If request/response contains sensitive information one might want to store it encrypted:

```
Path cacheDir = ...
SecretKey secretKey = ...
Cache encrypted = Cache.newDiskCacheBuilder()
.dir(cacheDir)
.encrypted()
.key(secretKey)
.cipherAlgorithm("AES")
.build();
```
will create persistent cache which encrypts data by user provided key.

### Decompression (gzip, deflate)
### Decompression
Here is an example of transparent encoding feature

```java
Expand Down

0 comments on commit aec3906

Please sign in to comment.