mirror of
https://github.com/gabehf/tempus.git
synced 2026-03-15 02:06:00 -07:00
TEST - Added a first form of cache for retrofit
This commit is contained in:
parent
2bf42aaeea
commit
340385aa85
11 changed files with 178 additions and 34 deletions
|
|
@ -0,0 +1,27 @@
|
|||
package com.cappielloantonio.play.subsonic.utils;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class CacheUtil {
|
||||
public static Interceptor onlineInterceptor = chain -> {
|
||||
okhttp3.Response response = chain.proceed(chain.request());
|
||||
int maxAge = 60;
|
||||
return response.newBuilder()
|
||||
.header("Cache-Control", "public, max-age=" + maxAge)
|
||||
.removeHeader("Pragma")
|
||||
.build();
|
||||
};
|
||||
|
||||
public static Interceptor offlineInterceptor = chain -> {
|
||||
Request request = chain.request();
|
||||
if (!false) {
|
||||
int maxStale = 60 * 60 * 24 * 30;
|
||||
request = request.newBuilder()
|
||||
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
|
||||
.removeHeader("Pragma")
|
||||
.build();
|
||||
}
|
||||
return chain.proceed(request);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue