您可以阅读此条目https://stackoverflow.com/a/18964588/2358095 以了解毕加索磁盘缓存的工作原理。
所以首先你必须在 ResponseCacheIcs 类中添加static void delete(Object cache) 方法。此类在 UrlConnectionDownloader.java 中定义。好像是这样的:
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) {
}
}
}
之后你必须添加
void clearDiskCache();
Downloader.java 中的方法。然后你必须在 UrlConnectionDownloader.java 和 OkHttpDownloader.java 中添加未实现的方法。您应该像这样在 UrlConnectionDownloader.java 中定义public void clearDiskCache() 方法:
@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);
}
}
然后你必须添加:
void clearDiskCache(){
downloader.clearDiskCache();
}
Dispacher.java 中的方法。然后添加:
public void clearDiskCache(){
dispatcher.clearDiskCache();
}
Picasso.java 中的方法。
宾果游戏!!!现在您可以在代码中调用clearDiskCache() 方法。这是一个例子:
Picasso picasso = Picasso.with(TestActivity.this);
picasso.clearDiskCache();
picasso.setDebugging(true);
picasso.setIndicatorsEnabled(true);
picasso.setLoggingEnabled(true);
picasso.load(imageURL).into(imageView);