问题
I use Glide library for Android. I want to set the cache in my custom folder, so the standard cache folder can be clean (with Master Clean for example). For this reason I use this code from manual, but this don't work for me.
My code:
DiskCache.Factory diskCacheFactory = new DiskCache.Factory() {
@Override
public DiskCache build() {
DiskCache diskCache = DiskLruCacheWrapper.get(getFilesDir(), 1024*1024*100);
return diskCache;
}
};
new GlideBuilder(this).setDiskCache(diskCacheFactory);
Glide.with(this)
.load("http://www.website.com/1.jpg")
.into(imageView);
After I run this app Glide saves the image in the default folder.
回答1:
Try use:
if (!Glide.isSetup()) {
GlideBuilder gb = new GlideBuilder(this);
DiskCache dlw = DiskLruCacheWrapper.get(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myCatch/"), 250 * 1024 * 1024);
gb.setDiskCache(dlw);
Glide.setup(gb);
}
回答2:
In Glide 3.5, Glide.isSetup() and Glide.setup() are deprecated. The best way to do this is to use GlideModules to do this kind of configuration lazily. Check out the wiki page on configuration.
来源:https://stackoverflow.com/questions/28540216/cant-set-glidebuilder