I'm trying to set a cache for Retrofit so that it does not have to retrieve the data constantly. I followed this SO as it appears to be in the right direction of what I need.
I have the following (which is identical from the SO)
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(REWRITE_CACHE_CONTROL_INTERCEPTOR);
File httpCacheDirectory = new File(getCacheDir(), "responses");
int cacheSize = 10*1024*1024;
Cache cache = new Cache(httpCacheDirectory, cacheSize);
client.setCache(cache);
However, client.setCache(cache)
returns an error cannot resolve method setCache
.
What am I doing wrong here? I have retrofit 2.1.0 and okhttp3 3.4.1