You can read this entry https://stackoverflow.com/a/18964588/2358095 to understand how picasso disk cache works.
So first of all you have to add static void delete(Object cache)
method in ResponseCacheIcs class. This class is defined in UrlConnectionDownloader.java. It seems like that:
private static class ResponseCacheIcs {
static Object install(Context context) throws IOException {
File cacheDir = Utils.createDefaultCacheDir(context);
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache == null) {
long maxSize = Utils.calculateDiskCacheSize(cacheDir);
cache = HttpResponseCache.install(cacheDir, maxSize);
}
return cache;
}
static void close(Object cache) {
try {
((HttpResponseCache) cache).close();
} catch (IOException ignored) {
}
}
static void delete(Object cache) {
try {
((HttpResponseCache) cache).delete();
} catch (IOException ignored) {
}
}
}
After that you have to add
void clearDiskCache();
method in Downloader.java. Then you have to add unimplemented method in UrlConnectionDownloader.java and OkHttpDownloader.java. You should define public void clearDiskCache()
method in UrlConnectionDownloader.java like this:
@Override
public void clearDiskCache() {
// TODO Auto-generated method stub
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && cache != null) {
ResponseCacheIcs.delete(cache);
}
}
Then you have to add:
void clearDiskCache(){
downloader.clearDiskCache();
}
method in Dispacher.java. And then add:
public void clearDiskCache(){
dispatcher.clearDiskCache();
}
method in Picasso.java.
Bingo!!! Now you can call clearDiskCache()
method in your code. Here is an example:
Picasso picasso = Picasso.with(TestActivity.this);
picasso.clearDiskCache();
picasso.setDebugging(true);
picasso.setIndicatorsEnabled(true);
picasso.setLoggingEnabled(true);
picasso.load(imageURL).into(imageView);