Android的毕加索图片库中清除磁盘/ SD卡缓存 [英] Clear Disk/SD Card Cache of Android's Picasso Image Library
问题描述
我使用的毕加索从我的服务器加载图像。它工作正常,但我加载图像,后来又改变了它。但毕加索在磁盘缓存的地方形象(我查了SD卡,并且找不到任何目录毕加索存储)。
I am using Picasso to load images from my server. It works fine, but I am loading an image, and changed it later. But Picasso has the image cached somewhere in disk (I checked the SD card, and could not find any directory that Picasso is storing in).
我试图删除缓存被接受的回答这个问题的建议:缓存失效毕加索
I tried to remove the cache as suggested by the accepted answer to this question : Invalidate cache in Picasso
我也尝试使用加载图像时跳过缓存:。Picasso.with(CTX).load(新文件(/路径/要/图像))skipMemoryCache()成(ImageView的)
I also tried skipping cache when loading images using : Picasso.with(ctx).load(new File("/path/to/image")).skipMemoryCache().into(imageView)
但这些方法都在工作。
But none of these methods are working.
感谢您的任何建议或暗示可以帮我过这个问题。
Thanks for any suggestion or hint that could help me pass this problem.
推荐答案
毕加索
磁盘映像在应用程序内部缓存目录缓存。再看方法 createDefaultCacheDir
此处<一个href=\"https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/Utils.java\" rel=\"nofollow\">https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/Utils.java
Picasso
disk images are cached in app internal cache directory . Look at the method createDefaultCacheDir
here https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/Utils.java
您可以清除所有图像 getCacheDir /毕加索缓存
像这样
You can clear all the images in getCacheDir/picasso-cache
like this
public boolean clearImageDiskCache() {
File cache = new File(mContext.getApplicationContext().getCacheDir(), "picasso-cache");
if (cache.exists() && cache.isDirectory()) {
return deleteDir(cache);
}
return false;
}
要删除目录下的所有文件
To delete all files in directory
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
这篇关于Android的毕加索图片库中清除磁盘/ SD卡缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!