根据documentation ,
The internal cache factory places the disk cache in your application's internal cache directory and sets a maximum size of 250MB.
当我尝试在我的应用程序中实现一些离线功能时,它可能需要大于 250MB 的缓存大小。那么 Glide 是否允许修改缓存大小,或者我需要找到一种替代方法来做这件事?如果是这样,我应该遵循什么机制?
我在documentation看到过一种增加它的方法。
builder.setDiskCache(
new InternalCacheDiskCacheFactory(context, yourSizeInBytes));
如何在我的代码中实现它?
最佳答案
参见 here .
You can set the size of the disk cache using the InternalCacheDiskCacheFactory.
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, yourSizeInBytes));
您可以像下面这样在您的项目中应用:
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.module.GlideModule;
import com.example.MyApplication;
import java.util.Locale;
public class LimitCacheSizeGlideModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
if (MyApplication.from(context).isTest())
return; // NOTE: StatFs will crash on robolectric.
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, yourSizeInBytes));
}
@Override
public void registerComponents(Context context, Glide glide) {
}
}
然后在你的 list 中这样添加
<manifest
...
<application>
<meta-data
android:name="YourPackageNameHere.LimitCacheSizeGlideModule"
android:value="GlideModule" />
...
</application>
</manifest>
关于android - 如何增加 Glide android 中的缓存大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46108915/