Reputation: 4742
Just like picasso has Picasso.with(context).invalidate(url) , Does okhttp have any mechanism for clearing a disk cache entry given a key?
Upvotes: 2
Views: 1042
Reputation: 320
As the user polbins stated here this seems like can be achieved like this.
public static void removeFromCache(String urlString) {
try {
Iterator<String> it = mCache.urls();
while (it.hasNext()) {
String next = it.next();
if (next.contains(urlString)) {
it.remove();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
mCache instance is the cache instance that you set to OkHttpClient, like this.
Cache cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024);
OkHttpClient client = new OkHttpClient();
client.setCache(cache);
Upvotes: 3