这里写自定义目录标题
Glide 清除特定图片缓存
本地使用的是Glide 4.16.0 版本,实现方式如下:
找到Url所对应的本地缓存
public static String getCacheFile(Context mContext, String url) {
DataCacheKey dataCacheKey = new DataCacheKey(new GlideUrl(url), EmptySignature.obtain());
SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator();
String safeKey = safeKeyGenerator.getSafeKey(dataCacheKey);
File file = new File(mContext.getCacheDir() + "/glide");
return file.getAbsolutePath()+"/"+safeKey+".0";
}
直接删除文件即可
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < Objects.requireNonNull(children).length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
assert dir != null;
return dir.delete();
}