在Application全局配置文件中:
//磁盘(路径)缓存
DiskCacheConfig cacheConfig = DiskCacheConfig.newBuilder(this)
.setBaseDirectoryPath(Environment.getDownloadCacheDirectory())
.setBaseDirectoryName("image/")
.build();
ImagePipelineConfig pipelineConfig = ImagePipelineConfig.newBuilder(this)
.setMainDiskCacheConfig(cacheConfig)
.build();
//初始化
Fresco.initialize(this,getConfigureCaches(this));
//设置缓存最大MAX
private static int MAX_MEM = 30 * ByteConstants.MB;
private ImagePipelineConfig getConfigureCaches(Context context){
final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
MAX_MEM,
Integer.MAX_VALUE,
MAX_MEM,
Integer.MAX_VALUE,
Integer.MAX_VALUE
);
Supplier<MemoryCacheParams> memoryCacheParamsSupplier = new Supplier<MemoryCacheParams>() {
@Override
public MemoryCacheParams get() {
return bitmapCacheParams;
}
};
ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context);
builder.setBitmapMemoryCacheParamsSupplier(memoryCacheParamsSupplier);
return builder.build();
}