我正在使用Glide库进行图像加载.我的应用程序中有很多图像,所以我想在缓存大小超过50 MB时清除缓存.
有人可以帮我这样做吗?
解决方法:
在UI线程外部调用Glide.get(context).clearDiskCache(). (同样考虑clearMemory()以防止在清除磁盘缓存后出现意外)这对我有用
new Thread(new Runnable() {
@Override
public void run() {
Glide.get(MainActivity.this).clearDiskCache();
}
}).start();
There is lot of images in my app so I want to clear cache once cache size is larger than 50 mb.
如果你想要限制50 mb你可以实现滑行模块
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;
import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.modu