Skip to content

Commit

Permalink
Update publish configuration and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ncornette committed Jun 22, 2016
1 parent f932158 commit af0eec7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# OkCacheControl
Helper class to configure cache behaviour of OkHttp client, also works with Retrofit for Android.
Helper class to configure cache behaviour of OkHttp client, also works
with Retrofit for Android.

## Usage

Initialize OkCacheControl with `OkHttpClient.Builder()`, then you can call 3 methods :
Initialize `OkCacheControl` with *OkHttpClient.Builder()*, then you can
call 3 methods :

- `overrideServerCachePolicy(MaxAgeControl)`
- `forceCacheWhenOffline(NetworkMonitor)`
Expand All @@ -21,15 +23,28 @@ Initialize OkCacheControl with `OkHttpClient.Builder()`, then you can call 3 met

## Description

- `overrideServerCachePolicy(MaxAgeControl)` will override server cache policy with `Cache-Control: max-age`
on responses. Cache will be used until expiration even if network is available. Use it when server doesn't
implement a cache policy.
- `forceCacheWhenOffline(NetworkMonitor)` will force the use of cache when no network connection is available.
When offline, cache will be used even if expired. for `Android` you can implement a `NetworkMonitor` that returns
the value of `ConnectivityManager.getActiveNetworkInfo().isConnected()`.

Call `apply()` to add interceptors to `OkHttpClient.Builder` then it returns the builder so you can continue to build
and add the cache.
- `overrideServerCachePolicy(MaxAgeControl)` will override server cache policy
on responses with *Cache-Control: max-age*. Cache will be used until expiration
even if network is available. Use it when server doesn't implement a cache policy!

- `forceCacheWhenOffline(NetworkMonitor)` will force the use of cache when
no network connection is available. When offline, cache will be used even
if expired. for Android you can implement a *NetworkMonitor* that returns
the value of *ConnectivityManager.getActiveNetworkInfo().isConnected()*.

Call `apply()` to add interceptors to *OkHttpClient.Builder* and return the
builder so you can continue to build *OkHttpClient* and add the cache.

### Per request cache control

without `Cache-Control` header, cache is used until expiration, then network.
(with `forceCacheWhenOffline()` expired cache will be used when offline)

- add `Cache-Control: no-cache` to always use network, cache will be used
only when offline.

- add `Cache-Control: no-store` to not store response in cache.

## Installation

Expand Down
6 changes: 5 additions & 1 deletion okcache-control/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ publishing {
}

bintray {
dryRun = false
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
publications = ['mavenJava']
pkg {
repo = 'generic'
repo = 'maven'
name = "${POM_ARTIFACTID}"
licenses = ['Apache-2.0']
vcsUrl = 'https://github.com/ncornette/OkCacheControl.git'
version {
name= "${POM_VERSION}"
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion okcache-control/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

POM_VERSION=1.0.0-SNAPSHOT
POM_VERSION=1.0.0
POM_ARTIFACTID=okcache-control
POM_GROUPID=com.ncornette.cache

Expand Down

0 comments on commit af0eec7

Please sign in to comment.