mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00: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
|
|
@ -54,6 +54,6 @@ public class App extends Application {
|
|||
preferences.setUsername(username);
|
||||
preferences.setAuthentication(password, token, salt);
|
||||
|
||||
return new Subsonic(preferences);
|
||||
return new Subsonic(context, preferences);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.cappielloantonio.play.subsonic;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient;
|
||||
import com.cappielloantonio.play.subsonic.api.browsing.BrowsingClient;
|
||||
import com.cappielloantonio.play.subsonic.api.mediaannotation.MediaAnnotationClient;
|
||||
|
|
@ -16,6 +18,8 @@ import java.util.Map;
|
|||
public class Subsonic {
|
||||
private static final Version API_MAX_VERSION = Version.of("1.15.0");
|
||||
|
||||
private final Context context;
|
||||
|
||||
private Version apiVersion = API_MAX_VERSION;
|
||||
private SubsonicPreferences preferences;
|
||||
|
||||
|
|
@ -28,7 +32,8 @@ public class Subsonic {
|
|||
private MediaAnnotationClient mediaAnnotationClient;
|
||||
private MediaLibraryScanningClient mediaLibraryScanningClient;
|
||||
|
||||
public Subsonic(SubsonicPreferences preferences) {
|
||||
public Subsonic(Context context, SubsonicPreferences preferences) {
|
||||
this.context = context;
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
|
|
@ -38,56 +43,56 @@ public class Subsonic {
|
|||
|
||||
public SystemClient getSystemClient() {
|
||||
if (systemClient == null) {
|
||||
systemClient = new SystemClient(this);
|
||||
systemClient = new SystemClient(context, this);
|
||||
}
|
||||
return systemClient;
|
||||
}
|
||||
|
||||
public BrowsingClient getBrowsingClient() {
|
||||
if (browsingClient == null) {
|
||||
browsingClient = new BrowsingClient(this);
|
||||
browsingClient = new BrowsingClient(context, this);
|
||||
}
|
||||
return browsingClient;
|
||||
}
|
||||
|
||||
public MediaRetrievalClient getMediaRetrievalClient() {
|
||||
if (mediaRetrievalClient == null) {
|
||||
mediaRetrievalClient = new MediaRetrievalClient(this);
|
||||
mediaRetrievalClient = new MediaRetrievalClient(context, this);
|
||||
}
|
||||
return mediaRetrievalClient;
|
||||
}
|
||||
|
||||
public PlaylistClient getPlaylistClient() {
|
||||
if (playlistClient == null) {
|
||||
playlistClient = new PlaylistClient(this);
|
||||
playlistClient = new PlaylistClient(context, this);
|
||||
}
|
||||
return playlistClient;
|
||||
}
|
||||
|
||||
public SearchingClient getSearchingClient() {
|
||||
if (searchingClient == null) {
|
||||
searchingClient = new SearchingClient(this);
|
||||
searchingClient = new SearchingClient(context, this);
|
||||
}
|
||||
return searchingClient;
|
||||
}
|
||||
|
||||
public AlbumSongListClient getAlbumSongListClient() {
|
||||
if (albumSongListClient == null) {
|
||||
albumSongListClient = new AlbumSongListClient(this);
|
||||
albumSongListClient = new AlbumSongListClient(context, this);
|
||||
}
|
||||
return albumSongListClient;
|
||||
}
|
||||
|
||||
public MediaAnnotationClient getMediaAnnotationClient() {
|
||||
if (mediaAnnotationClient == null) {
|
||||
mediaAnnotationClient = new MediaAnnotationClient(this);
|
||||
mediaAnnotationClient = new MediaAnnotationClient(context, this);
|
||||
}
|
||||
return mediaAnnotationClient;
|
||||
}
|
||||
|
||||
public MediaLibraryScanningClient getMediaLibraryScanningClient() {
|
||||
if (mediaLibraryScanningClient == null) {
|
||||
mediaLibraryScanningClient = new MediaLibraryScanningClient(this);
|
||||
mediaLibraryScanningClient = new MediaLibraryScanningClient(context, this);
|
||||
}
|
||||
return mediaLibraryScanningClient;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.cappielloantonio.play.subsonic.api.albumsonglist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -14,11 +18,13 @@ import retrofit2.Retrofit;
|
|||
public class AlbumSongListClient {
|
||||
private static final String TAG = "BrowsingClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private AlbumSongListService albumSongListService;
|
||||
private final AlbumSongListService albumSongListService;
|
||||
|
||||
public AlbumSongListClient(Subsonic subsonic) {
|
||||
public AlbumSongListClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -68,6 +74,9 @@ public class AlbumSongListClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -77,4 +86,9 @@ public class AlbumSongListClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.cappielloantonio.play.subsonic.api.browsing;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -14,11 +18,13 @@ import retrofit2.Retrofit;
|
|||
public class BrowsingClient {
|
||||
private static final String TAG = "BrowsingClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private BrowsingService browsingService;
|
||||
private final BrowsingService browsingService;
|
||||
|
||||
public BrowsingClient(Subsonic subsonic) {
|
||||
public BrowsingClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -118,6 +124,9 @@ public class BrowsingClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -127,4 +136,9 @@ public class BrowsingClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.cappielloantonio.play.subsonic.api.mediaannotation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -14,11 +18,13 @@ import retrofit2.Retrofit;
|
|||
public class MediaAnnotationClient {
|
||||
private static final String TAG = "BrowsingClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private MediaAnnotationService mediaAnnotationService;
|
||||
private final MediaAnnotationService mediaAnnotationService;
|
||||
|
||||
public MediaAnnotationClient(Subsonic subsonic) {
|
||||
public MediaAnnotationClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -53,6 +59,9 @@ public class MediaAnnotationClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -62,4 +71,9 @@ public class MediaAnnotationClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
package com.cappielloantonio.play.subsonic.api.medialibraryscanning;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.api.system.SystemService;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -15,11 +19,13 @@ import retrofit2.Retrofit;
|
|||
public class MediaLibraryScanningClient {
|
||||
private static final String TAG = "SystemClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private MediaLibraryScanningService mediaLibraryScanningService;
|
||||
private final MediaLibraryScanningService mediaLibraryScanningService;
|
||||
|
||||
public MediaLibraryScanningClient(Subsonic subsonic) {
|
||||
public MediaLibraryScanningClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -44,6 +50,9 @@ public class MediaLibraryScanningClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -53,4 +62,9 @@ public class MediaLibraryScanningClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.cappielloantonio.play.subsonic.api.mediaretrieval;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -14,11 +18,13 @@ import retrofit2.Retrofit;
|
|||
public class MediaRetrievalClient {
|
||||
private static final String TAG = "BrowsingClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private MediaRetrievalService mediaRetrievalService;
|
||||
private final MediaRetrievalService mediaRetrievalService;
|
||||
|
||||
public MediaRetrievalClient(Subsonic subsonic) {
|
||||
public MediaRetrievalClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -43,6 +49,9 @@ public class MediaRetrievalClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -52,4 +61,9 @@ public class MediaRetrievalClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
package com.cappielloantonio.play.subsonic.api.playlist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -16,11 +20,13 @@ import retrofit2.Retrofit;
|
|||
public class PlaylistClient {
|
||||
private static final String TAG = "BrowsingClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private PlaylistService playlistService;
|
||||
private final PlaylistService playlistService;
|
||||
|
||||
public PlaylistClient(Subsonic subsonic) {
|
||||
public PlaylistClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -60,6 +66,9 @@ public class PlaylistClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -69,4 +78,9 @@ public class PlaylistClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.cappielloantonio.play.subsonic.api.searching;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -14,11 +18,13 @@ import retrofit2.Retrofit;
|
|||
public class SearchingClient {
|
||||
private static final String TAG = "BrowsingClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private SearchingService searchingService;
|
||||
private final SearchingService searchingService;
|
||||
|
||||
public SearchingClient(Subsonic subsonic) {
|
||||
public SearchingClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -43,6 +49,9 @@ public class SearchingClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -52,4 +61,9 @@ public class SearchingClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package com.cappielloantonio.play.subsonic.api.system;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.subsonic.Subsonic;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.subsonic.utils.CacheUtil;
|
||||
import com.tickaroo.tikxml.retrofit.TikXmlConverterFactory;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -14,11 +18,13 @@ import retrofit2.Retrofit;
|
|||
public class SystemClient {
|
||||
private static final String TAG = "SystemClient";
|
||||
|
||||
private Subsonic subsonic;
|
||||
private final Context context;
|
||||
private final Subsonic subsonic;
|
||||
private Retrofit retrofit;
|
||||
private SystemService systemService;
|
||||
private final SystemService systemService;
|
||||
|
||||
public SystemClient(Subsonic subsonic) {
|
||||
public SystemClient(Context context, Subsonic subsonic) {
|
||||
this.context = context;
|
||||
this.subsonic = subsonic;
|
||||
|
||||
this.retrofit = new Retrofit.Builder()
|
||||
|
|
@ -43,6 +49,9 @@ public class SystemClient {
|
|||
private OkHttpClient getOkHttpClient() {
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.addInterceptor(CacheUtil.offlineInterceptor)
|
||||
.addNetworkInterceptor(CacheUtil.onlineInterceptor)
|
||||
.cache(getCache())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -52,4 +61,9 @@ public class SystemClient {
|
|||
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
int cacheSize = 10 * 1024 * 1024;
|
||||
return new Cache(context.getCacheDir(), cacheSize);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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