Skip to content

Commit

Permalink
Add overrideServerCachePolicy(Long), bump v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ncornette committed Jul 10, 2016
1 parent e0d7c9b commit 7f5946a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ 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.1.0-SNAPSHOT
# publish with
POM_VERSION=1.1.0
POM_GROUPID=com.ncornette.cache

POM_DESCRIPTION=Helper class to configure cache behaviour of OkHttp client and Retrofit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ private OkCacheControl(OkHttpClient.Builder okBuilder) {
this.okBuilder = okBuilder;
}

public OkCacheControl overrideServerCachePolicy(Long maxAgeSeconds) {
if (maxAgeSeconds == null) {
return this.overrideServerCachePolicy(0, null);
} else {
return this.overrideServerCachePolicy(maxAgeSeconds, TimeUnit.SECONDS);
}
}

public OkCacheControl overrideServerCachePolicy(long timeValue, TimeUnit unit) {
this.maxAgeControl = null;
this.maxAgeValue = timeValue;
Expand Down
31 changes: 31 additions & 0 deletions okcache-control/src/test/java/com/ncornette/cache/BuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,37 @@ public void testOverrideServerCachePolicy_DYNAMIC() throws Exception {
then(response.header("Cache-Control")).isEqualTo("max-age=300");
}

@Test
public void testOverrideServerCachePolicy_LONG_NULL() throws Exception {
//given
OkHttpClient client = OkCacheControl.on(new OkHttpClient.Builder())
.overrideServerCachePolicy((Long)null)
.apply().build();

//when
mockWebServer.enqueue(new MockResponse().setBody("Response"));
Response response = getResponse(client);

//then
then(response.header("Cache-Control")).isNull();
}

@Test
public void testOverrideServerCachePolicy_LONG() throws Exception {
//given
OkHttpClient client = OkCacheControl.on(new OkHttpClient.Builder())
.overrideServerCachePolicy(TimeUnit.SECONDS.convert(5, TimeUnit.MINUTES))
.apply().build();

//when
mockWebServer.enqueue(new MockResponse().setBody("Response"));
Response response = getResponse(client);

//then
then(response.header("Cache-Control")).isEqualTo(
"max-age="+TimeUnit.SECONDS.convert(5, TimeUnit.MINUTES));
}


@Test
public void testOverrideServerCachePolicy_STATIC() throws Exception {
Expand Down

0 comments on commit 7f5946a

Please sign in to comment.