TEST - Added a first form of cache for retrofit

This commit is contained in:
CappielloAntonio
2021-08-23 23:00:56 +02:00
parent 2bf42aaeea
commit 340385aa85
11 changed files with 178 additions and 34 deletions

View File

@@ -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);
};
}