You can read this post at https://stackoverflow.com/a/166268/127 to understand how picasso disk cache works.
First of all, you need to add the static void delete(Object cache) method to the ResponseCacheIcs class. This class is defined in UrlConnectionDownloader.java. It looks like this:
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 should add
void clearDiskCache();
in Downloader.java. Then you must add the unrealized method to UrlConnectionDownloader.java and OkHttpDownloader.java. You must define the public void clearDiskCache() method in UrlConnectionDownloader.java as follows:
@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 should add:
void clearDiskCache(){ downloader.clearDiskCache(); }
in Dispacher.java. Then add:
public void clearDiskCache(){ dispatcher.clearDiskCache(); }
in Picasso.java.
Bingo!!! Now you can call the 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);
Javat
source share