@GlideModule
public class GlideCache extends AppGlideModule {
private static final int DISK_CACHE_SIZE = 100 * 1024 * 1024;
public static final int MAX_MEMORY_CACHE_SIZE = 10 * 1024 * 1024;
private String appRootPath;
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
//设置磁盘缓存的路径 path
appRootPath = context.getCacheDir().getPath();
final File cacheDir = new File(appRootPath);
builder.setDiskCache(new DiskCache.Factory() {
@Override
public DiskCache build() {
return DiskLruCacheWrapper.get(cacheDir, DISK_CACHE_SIZE);
}
});
//设置内存缓存大小,一般默认使用glide内部的默认值
builder.setMemoryCache(new LruResourceCache(MAX_MEMORY_CACHE_SIZE));
}
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
super.registerComponents(context, glide, registry);
}
}
<meta-data
android:name="com.wd.practice_base.cache.GlideCache"
android:value="GlideCache" />
Glide.with(getContext()).asBitmap()
.load(resultBean.getMasterPic())
.skipMemoryCache( true )
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.transform(new GlideCircleWithBorder(getContext(), 2, Color.parseColor("#ffffff")))
.into((ImageView) baseViewHolder.findView(R.id.pics));