com.facebook.cache.disk.DiskCacheConfig Java Examples

The following examples show how to use com.facebook.cache.disk.DiskCacheConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImagePipelineConfigFactory.java    From fresco with MIT License 6 votes vote down vote up
/** Configures disk and memory cache not to exceed common limits */
private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) {
  final MemoryCacheParams bitmapCacheParams =
      new MemoryCacheParams(
          ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
          Integer.MAX_VALUE, // Max entries in the cache
          ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
          Integer.MAX_VALUE, // Max length of eviction queue
          Integer.MAX_VALUE, // Max cache entry size
          TimeUnit.MINUTES.toMillis(5)); // Interval for checking cache parameters
  configBuilder
      .setBitmapMemoryCacheParamsSupplier(
          new Supplier<MemoryCacheParams>() {
            public MemoryCacheParams get() {
              return bitmapCacheParams;
            }
          })
      .setMainDiskCacheConfig(
          DiskCacheConfig.newBuilder(context)
              .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
              .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
              .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE)
              .build());
}
 
Example #2
Source File: BoxingFrescoLoader.java    From boxing with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context)
            .setDownsampleEnabled(true);
    String cache = BoxingFileHelper.getCacheDir(context);

    if (TextUtils.isEmpty(cache)) {
        throw new IllegalStateException("the cache dir is null");
    }
    if (!TextUtils.isEmpty(cache)) {
        DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
                .setBaseDirectoryPath(new File(cache))
                .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
                .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
                .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)
                .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)
                .build();
        builder.setMainDiskCacheConfig(diskCacheConfig);
    }
    ImagePipelineConfig config = builder.build();
    Fresco.initialize(context, config);
}
 
Example #3
Source File: FrescoConfigFactory.java    From ImageLoadPK with Apache License 2.0 6 votes vote down vote up
public static ImagePipelineConfig getImagePipelineConfig(Context context) {
    if (sImagePipelineConfig == null) {
        sImagePipelineConfig = ImagePipelineConfig.newBuilder(context)
                .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                        .setMaxCacheSize(ConfigConstants.MAX_CACHE_DISK_SIZE)
                        .build())
                .setBitmapMemoryCacheParamsSupplier(
                        new Supplier<MemoryCacheParams>() {
                            @Override
                            public MemoryCacheParams get() {
                                return new MemoryCacheParams(ConfigConstants.MAX_CACHE_MEMORY_SIZE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE,
                                        Integer.MAX_VALUE);
                            }
                        }
                )
                .build();
    }
    return sImagePipelineConfig;
}
 
Example #4
Source File: ImagePipelineConfigFactory.java    From ZhiHu-TopAnswer with Apache License 2.0 6 votes vote down vote up
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(
    ImagePipelineConfig.Builder configBuilder,
    Context context) {
  final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
      MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
      Integer.MAX_VALUE,                     // Max entries in the cache
      MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
      Integer.MAX_VALUE,                     // Max length of eviction queue
      Integer.MAX_VALUE);                    // Max cache entry size
  configBuilder
      .setBitmapMemoryCacheParamsSupplier(
          new Supplier<MemoryCacheParams>() {
            public MemoryCacheParams get() {
              return bitmapCacheParams;
            }
          })
      .setMainDiskCacheConfig(
          DiskCacheConfig.newBuilder(context)
              .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
              .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)
              .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
              .build());
}
 
Example #5
Source File: Elephant.java    From Elephant with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    applicationContext = this;

    /**
     * 设置 Fresco 图片缓存的路径
     */
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(getApplicationContext())
            .setBaseDirectoryPath(getOwnCacheDirectory(this, APP_CACHE_PATH))
            .build();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(getApplicationContext())
            .setMainDiskCacheConfig(diskCacheConfig)
            .setSmallImageDiskCacheConfig(diskCacheConfig)
            .build();

    //初始化 Fresco 图片缓存库
    Fresco.initialize(this, config);
    //初始化日志输出工具
    JLog.initialize(BuildConfig.LOG_DEBUG);
}
 
Example #6
Source File: FrescoUtils.java    From FrescoUtlis with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化操作,建议在子线程中进行
 * 添加的依赖:
 *  compile 'com.facebook.fresco:fresco:0.10.0+'
    compile 'com.facebook.fresco:animated-webp:0.10.0'
    compile 'com.facebook.fresco:animated-gif:0.10.0'
 * @param context
 * @param cacheSizeInM  磁盘缓存的大小,以M为单位
 */
public static void init(final Context context,int cacheSizeInM){


    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(cacheSizeInM*1024*1024)
            .setBaseDirectoryName(PHOTO_FRESCO)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return context.getCacheDir();
                }
            })
            .build();
    MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker();
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(diskCacheConfig)
            .setImageCacheStatsTracker(imageCacheStatsTracker)
            .setDownsampleEnabled(true)//Downsampling,它处理图片的速度比常规的裁剪更快,
            // 并且同时支持PNG,JPG以及WEP格式的图片,非常强大,与ResizeOptions配合使用
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .build();
    Fresco.initialize(context, config);
}
 
Example #7
Source File: DiskStorageCacheFactory.java    From fresco with MIT License 6 votes vote down vote up
public static DiskStorageCache buildDiskStorageCache(
    DiskCacheConfig diskCacheConfig,
    DiskStorage diskStorage,
    Executor executorForBackgroundInit) {
  DiskStorageCache.Params params =
      new DiskStorageCache.Params(
          diskCacheConfig.getMinimumSizeLimit(),
          diskCacheConfig.getLowDiskSpaceSizeLimit(),
          diskCacheConfig.getDefaultSizeLimit());

  return new DiskStorageCache(
      diskStorage,
      diskCacheConfig.getEntryEvictionComparatorSupplier(),
      params,
      diskCacheConfig.getCacheEventListener(),
      diskCacheConfig.getCacheErrorLogger(),
      diskCacheConfig.getDiskTrimmableRegistry(),
      executorForBackgroundInit,
      diskCacheConfig.getIndexPopulateAtStartupEnabled());
}
 
Example #8
Source File: MyApplication.java    From TLint with Apache License 2.0 6 votes vote down vote up
private void initFrescoConfig() {
    final MemoryCacheParams bitmapCacheParams =
            new MemoryCacheParams(MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
                    Integer.MAX_VALUE,                     // Max entries in the cache
                    MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
                    Integer.MAX_VALUE,                     // Max length of eviction queue
                    Integer.MAX_VALUE);
    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, mOkHttpClient)
            .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig())
            .setBitmapMemoryCacheParamsSupplier(new Supplier<MemoryCacheParams>() {
                public MemoryCacheParams get() {
                    return bitmapCacheParams;
                }
            })
            .setMainDiskCacheConfig(
                    DiskCacheConfig.newBuilder(this).setMaxCacheSize(MAX_DISK_CACHE_SIZE).build())
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, config);
}
 
Example #9
Source File: ImagePipelineConfigFactory.java    From meiShi with Apache License 2.0 6 votes vote down vote up
/**
 * Configures disk and memory cache not to exceed common limits
 */
private static void configureCaches(
        ImagePipelineConfig.Builder configBuilder,
        Context context) {
    FileUtils.createDirs(ConfigConstants.IMAGE_PIPELINE_CACHE_DIR);
    final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
            ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache
            Integer.MAX_VALUE,                     // Max entries in the cache
            ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue
            Integer.MAX_VALUE,                     // Max length of eviction queue
            Integer.MAX_VALUE);                    // Max cache entry size
    configBuilder
            .setBitmapMemoryCacheParamsSupplier(
                    new Supplier<MemoryCacheParams>() {
                        public MemoryCacheParams get() {
                            return bitmapCacheParams;
                        }
                    })
            .setMainDiskCacheConfig(
                    DiskCacheConfig.newBuilder(context)
                            .setBaseDirectoryPath(FileUtils.createDirs(ConfigConstants.IMAGE_PIPELINE_BASE_DIR))
                            .setBaseDirectoryName(ConfigConstants.IMAGE_PIPELINE_CACHE_DIR)
                            .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE)
                            .build());
}
 
Example #10
Source File: FrescoLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final Context context, int cacheSizeInM) {
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(cacheSizeInM*1024*1024)
            .setBaseDirectoryName(GlobalConfig.cacheFolderName)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return context.getCacheDir();
                }
            })
            .build();
    MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker();

    OkHttpClient okHttpClient= MyUtil.getClient(GlobalConfig.ignoreCertificateVerify);
    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(context,okHttpClient)
            //ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(diskCacheConfig)
            .setImageCacheStatsTracker(imageCacheStatsTracker)
            .setDownsampleEnabled(true)//Downsampling,它处理图片的速度比常规的裁剪更快,
            // 并且同时支持PNG,JPG以及WEP格式的图片,非常强大,与ResizeOptions配合使用
            .setBitmapsConfig(Bitmap.Config.RGB_565)

            //让fresco即时清理内存:http://blog.csdn.net/honjane/article/details/65629799
            .setBitmapMemoryCacheParamsSupplier(new MyBitmapMemoryCacheParamsSupplier((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)))
            .build();
    //Fresco.initialize(context, config);

    BigImageViewer.initialize(BigImageLoader.with(context,config));

}
 
Example #11
Source File: ImagePipelineFactory.java    From fresco with MIT License 5 votes vote down vote up
public FileCache getSmallImageFileCache() {
  if (mSmallImageFileCache == null) {
    DiskCacheConfig diskCacheConfig = mConfig.getSmallImageDiskCacheConfig();
    mSmallImageFileCache = mConfig.getFileCacheFactory().get(diskCacheConfig);
  }
  return mSmallImageFileCache;
}
 
Example #12
Source File: ImagePipelineFactory.java    From fresco with MIT License 5 votes vote down vote up
public FileCache getMainFileCache() {
  if (mMainFileCache == null) {
    DiskCacheConfig diskCacheConfig = mConfig.getMainDiskCacheConfig();
    mMainFileCache = mConfig.getFileCacheFactory().get(diskCacheConfig);
  }
  return mMainFileCache;
}
 
Example #13
Source File: ImagePipelineConfig.java    From fresco with MIT License 5 votes vote down vote up
private static DiskCacheConfig getDefaultMainDiskCacheConfig(final Context context) {
  try {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.beginSection("DiskCacheConfig.getDefaultMainDiskCacheConfig");
    }
    return DiskCacheConfig.newBuilder(context).build();
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example #14
Source File: DynamicDefaultDiskStorageFactory.java    From fresco with MIT License 5 votes vote down vote up
@Override
public DiskStorage get(DiskCacheConfig diskCacheConfig) {
  return new DynamicDefaultDiskStorage(
      diskCacheConfig.getVersion(),
      diskCacheConfig.getBaseDirectoryPathSupplier(),
      diskCacheConfig.getBaseDirectoryName(),
      diskCacheConfig.getCacheErrorLogger());
}
 
Example #15
Source File: ImageUtil.java    From ONE-Unofficial with Apache License 2.0 5 votes vote down vote up
public static void init(Context context) {
    File cacheDir = new File(FileManager.getAppDir());

    //Fresco配置和初始化
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder()
            .setBaseDirectoryPath(cacheDir)                     //缓存文件夹所在的路径
            .setBaseDirectoryName(FileManager.DIR_IMG_CACHE)    //缓存文件夹名称
            .setMaxCacheSize(MAX_IMG_CACHE_SIZE).build();       //最大缓存文件大小,必须设置
    ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(context).setMainDiskCacheConfig(diskCacheConfig).build();
    Fresco.initialize(context, imagePipelineConfig);
}
 
Example #16
Source File: FrescoManager.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
public static void init(Context context, File baseDirectoryPath) {
    ImagePipelineConfig.Builder imagePipelineConfigBuilder = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
                    .setBaseDirectoryPath(baseDirectoryPath)
                    .setBaseDirectoryName("original")
                    .build())
            .setDownsampleEnabled(true);
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    Supplier<MemoryCacheParams> memoryCacheParamsSupplier = new DefaultBitmapMemoryCacheParamsSupplier(activityManager) {
        @Override
        public MemoryCacheParams get() {
            int maxCacheEntries = 256;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                maxCacheEntries = 64;
            }
            return new MemoryCacheParams(
                    getMaxCacheSize(),
                    maxCacheEntries,
                    Integer.MAX_VALUE,
                    Integer.MAX_VALUE,
                    Integer.MAX_VALUE);
        }
        private int getMaxCacheSize() {
            final int maxMemory = Math.min(activityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE);

            if (maxMemory < 32 * ByteConstants.MB) {
                return 4 * ByteConstants.MB;
            } else if (maxMemory < 64 * ByteConstants.MB) {
                return 6 * ByteConstants.MB;
            } else {
                return maxMemory / 4;
            }
        }
    };
    imagePipelineConfigBuilder.setBitmapMemoryCacheParamsSupplier(memoryCacheParamsSupplier);
    Fresco.initialize(context, imagePipelineConfigBuilder.build());
}
 
Example #17
Source File: MyApplication.java    From PicKing with Apache License 2.0 5 votes vote down vote up
private DiskCacheConfig getDiskCacheConfig() {
    return DiskCacheConfig.newBuilder(this)
            .setBaseDirectoryPath(getDiskCacheDir(this))
            .setBaseDirectoryName("ImagePipelineCacheDefault")
            .setMaxCacheSize(MAX_DISK_CACHE_SIZE)
            .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)
            .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE)
            .setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance())
            .build();
}
 
Example #18
Source File: FrescoUtil.java    From MyImageUtil with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化操作,在Application的onCreate方法中初始化,建议在子线程中进行
 *
 * 添加的依赖:
             compile 'com.facebook.fresco:fresco:0.12.0'
             // 在 API < 14 上的机器支持 WebP 时,需要添加
             compile 'com.facebook.fresco:animated-base-support:0.12.0'
             // 支持 GIF 动图,需要添加
             compile 'com.facebook.fresco:animated-gif:0.12.0'
             // 支持 WebP (静态图+动图),需要添加
             compile 'com.facebook.fresco:animated-webp:0.12.0'
             compile 'com.facebook.fresco:webpsupport:0.12.0'
             compile "com.facebook.fresco:imagepipeline-okhttp3:0.12.0+"
 * @param context
 * @param cacheSizeInM  磁盘缓存的大小,以M为单位

 */
public static void init(final Context context, int cacheSizeInM){
    isWWW = true;
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
            .setMaxCacheSize(cacheSizeInM*1024*1024)
            .setBaseDirectoryName(PHOTO_FRESCO)
            .setBaseDirectoryPathSupplier(new Supplier<File>() {
                @Override
                public File get() {
                    return context.getCacheDir();
                }
            })
            .build();
    MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker();


    OkHttpClient okHttpClient= getAllPassClient(context);


    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(context,okHttpClient)
   // ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context)
            .setMainDiskCacheConfig(diskCacheConfig)
            .setImageCacheStatsTracker(imageCacheStatsTracker)
            .setDownsampleEnabled(true)//Downsampling,它处理图片的速度比常规的裁剪更快,
            // 并且同时支持PNG,JPG以及WEP格式的图片,非常强大,与ResizeOptions配合使用
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .build();
    Fresco.initialize(context, config);

    WindowManager wm = (WindowManager) context.getSystemService(
            Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    screenWidth = display.getWidth() - dip2px(context,15);
}
 
Example #19
Source File: ImagePipelineConfig.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private static DiskCacheConfig getDefaultMainDiskCacheConfig(Context context) {
  return DiskCacheConfig.newBuilder()
      .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
      .setBaseDirectoryName("image_cache")
      .setMaxCacheSize(40 * ByteConstants.MB)
      .setMaxCacheSizeOnLowDiskSpace(10 * ByteConstants.MB)
      .setMaxCacheSizeOnVeryLowDiskSpace(2 * ByteConstants.MB)
      .build();
}
 
Example #20
Source File: FrescoPlusInitializer.java    From FrescoPlus with Apache License 2.0 5 votes vote down vote up
private void initialize(FrescoPlusConfig config) {
    final FrescoPlusConfig frescoPlusConfig;
    if (config == null)
        config = FrescoPlusConfig.newBuilder(mContext).build();
    frescoPlusConfig = config;

    isDebug = frescoPlusConfig.isDebug();
    logTag = frescoPlusConfig.getLogTag();

    printWDImageConfigLog(frescoPlusConfig);

    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder()
            .setBaseDirectoryName(DefaultConfigCentre.DEFAULT_DISK_CACHE_DIR_NAME)
            .setBaseDirectoryPath(frescoPlusConfig.getDiskCacheDir())
            .setMaxCacheSize(frescoPlusConfig.getMaxDiskCacheSize() * DefaultConfigCentre.MB)
            .setMaxCacheSizeOnLowDiskSpace(DefaultConfigCentre.DEFAULT_LOW_SPACE_DISK_CACHE_SIZE)
            .setMaxCacheSizeOnVeryLowDiskSpace(DefaultConfigCentre.DEFAULT_VERY_LOW_SPACE_DISK_CACHE_SIZE)
            .build();

    ImagePipelineConfig pipelineConfig = ImagePipelineConfig.newBuilder(mContext)
            .setBitmapsConfig(frescoPlusConfig.getBitmapConfig())
            .setImageCacheStatsTracker(FrescoCacheStatsTracker.getInstance())
            .setDownsampleEnabled(true)
            .setResizeAndRotateEnabledForNetwork(true)
            .setMainDiskCacheConfig(diskCacheConfig)
            .build();

    FrescoPlusCore.init(mContext, pipelineConfig);
}
 
Example #21
Source File: ImagePipelineConfig.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
public Builder setSmallImageDiskCacheConfig(DiskCacheConfig smallImageDiskCacheConfig) {
  mSmallImageDiskCacheConfig = smallImageDiskCacheConfig;
  return this;
}
 
Example #22
Source File: FrescoConfig.java    From BlueBoard with Apache License 2.0 4 votes vote down vote up
/**
     * 初始化配置
     */
    private static ImagePipelineConfig configureCaches(Context context) {
        //内存配置
        final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
                FrescoConfig.MAX_MEMORY_CACHE_SIZE, // 内存缓存中总图片的最大大小,以字节为单位。
                Integer.MAX_VALUE,                     // 内存缓存中图片的最大数量。
                FrescoConfig.MAX_MEMORY_CACHE_SIZE, // 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。
                Integer.MAX_VALUE,                     // 内存缓存中准备清除的总图片的最大数量。
                Integer.MAX_VALUE);                    // 内存缓存中单个图片的最大大小。

        //修改内存图片缓存数量,空间策略(这个方式有点恶心)
        Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() {
            @Override
            public MemoryCacheParams get() {
                return bitmapCacheParams;
            }
        };

        //小图片的磁盘配置
        DiskCacheConfig diskSmallCacheConfig = DiskCacheConfig.newBuilder(context)
                .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())//缓存图片基路径
                .setBaseDirectoryName(IMAGE_PIPELINE_SMALL_CACHE_DIR)//文件夹名
//            .setCacheErrorLogger(cacheErrorLogger)//日志记录器用于日志错误的缓存。
//            .setCacheEventListener(cacheEventListener)//缓存事件侦听器。
//            .setDiskTrimmableRegistry(diskTrimmableRegistry)//类将包含一个注册表的缓存减少磁盘空间的环境。
                .setMaxCacheSize(FrescoConfig.MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。
                .setMaxCacheSizeOnLowDiskSpace(MAX_SMALL_DISK_LOW_CACHE_SIZE)//缓存的最大大小,使用设备时低磁盘空间。
                .setMaxCacheSizeOnVeryLowDiskSpace(MAX_SMALL_DISK_VERYLOW_CACHE_SIZE)//缓存的最大大小,当设备极低磁盘空间
//            .setVersion(version)
                .build();

        //默认图片的磁盘配置
        DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
                .setBaseDirectoryPath(context.getExternalCacheDir().getAbsoluteFile())//缓存图片基路径
                .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR)//文件夹名
//            .setCacheErrorLogger(cacheErrorLogger)//日志记录器用于日志错误的缓存。
//            .setCacheEventListener(cacheEventListener)//缓存事件侦听器。
//            .setDiskTrimmableRegistry(diskTrimmableRegistry)//类将包含一个注册表的缓存减少磁盘空间的环境。
                .setMaxCacheSize(FrescoConfig.MAX_DISK_CACHE_SIZE)//默认缓存的最大大小。
                .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE)//缓存的最大大小,使用设备时低磁盘空间。
                .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERY_LOW_SIZE)//缓存的最大大小,当设备极低磁盘空间
//            .setVersion(version)
                .build();

        //缓存图片配置
        ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context)

//		ImagePipelineConfig.Builder configBuilder = OkHttpImagePipelineConfigFactory
//				.newBuilder(context, new OkHttpClient())

//            .setAnimatedImageFactory(AnimatedImageFactory animatedImageFactory)//图片加载动画
                .setBitmapMemoryCacheParamsSupplier(mSupplierMemoryCacheParams)//内存缓存配置(一级缓存,已解码的图片)
//            .setCacheKeyFactory(cacheKeyFactory)//缓存Key工厂
//            .setEncodedMemoryCacheParamsSupplier(encodedCacheParamsSupplier)//内存缓存和未解码的内存缓存的配置(二级缓存)
//            .setExecutorSupplier(executorSupplier)//线程池配置
//            .setImageCacheStatsTracker(imageCacheStatsTracker)//统计缓存的命中率
//            .setImageDecoder(ImageDecoder imageDecoder) //图片解码器配置
//            .setIsPrefetchEnabledSupplier(Supplier<Boolean> isPrefetchEnabledSupplier)//图片预览(缩略图,预加载图等)预加载到文件缓存
                .setMainDiskCacheConfig(diskCacheConfig)//磁盘缓存配置(总,三级缓存)
//            .setMemoryTrimmableRegistry(memoryTrimmableRegistry) //内存用量的缩减,有时我们可能会想缩小内存用量。比如应用中有其他数据需要占用内存,不得不把图片缓存清除或者减小 或者我们想检查看看手机是否已经内存不够了。
//            .setNetworkFetchProducer(networkFetchProducer)//自定的网络层配置:如OkHttp,Volley
//            .setPoolFactory(poolFactory)//线程池工厂配置
//            .setProgressiveJpegConfig(progressiveJpegConfig)//渐进式JPEG图
//            .setRequestListeners(requestListeners)//图片请求监听
//            .setResizeAndRotateEnabledForNetwork(boolean resizeAndRotateEnabledForNetwork)//调整和旋转是否支持网络图片
                .setSmallImageDiskCacheConfig(diskSmallCacheConfig);//磁盘缓存配置(小图片,可选~三级缓存的小图优化缓存)

        return configBuilder.build();
    }
 
Example #23
Source File: FrescoImageLoader.java    From FimiX8-RE with MIT License 4 votes vote down vote up
private static void configureCaches(Builder configBuilder, Context context) {
    MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(MAX_MEMORY_CACHE_SIZE, Integer.MAX_VALUE, MAX_MEMORY_CACHE_SIZE, Integer.MAX_VALUE, Integer.MAX_VALUE);
    configBuilder.setDownsampleEnabled(true).setBitmapsConfig(Config.RGB_565).setBitmapMemoryCacheParamsSupplier(new MyBitmapMemoryCacheParamsSupplier((ActivityManager) context.getSystemService("activity"))).setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context).setBaseDirectoryPath(context.getApplicationContext().getCacheDir()).setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR).setMaxCacheSize(41943040).build());
}
 
Example #24
Source File: ImagePipelineConfig.java    From fresco with MIT License 4 votes vote down vote up
public Builder setSmallImageDiskCacheConfig(DiskCacheConfig smallImageDiskCacheConfig) {
  mSmallImageDiskCacheConfig = smallImageDiskCacheConfig;
  return this;
}
 
Example #25
Source File: ImagePipelineConfig.java    From fresco with MIT License 4 votes vote down vote up
public Builder setMainDiskCacheConfig(DiskCacheConfig mainDiskCacheConfig) {
  mMainDiskCacheConfig = mainDiskCacheConfig;
  return this;
}
 
Example #26
Source File: ImagePipelineConfig.java    From fresco with MIT License 4 votes vote down vote up
public DiskCacheConfig getSmallImageDiskCacheConfig() {
  return mSmallImageDiskCacheConfig;
}
 
Example #27
Source File: ImagePipelineConfig.java    From fresco with MIT License 4 votes vote down vote up
public DiskCacheConfig getMainDiskCacheConfig() {
  return mMainDiskCacheConfig;
}
 
Example #28
Source File: DiskStorageCacheFactory.java    From fresco with MIT License 4 votes vote down vote up
@Override
public FileCache get(DiskCacheConfig diskCacheConfig) {
  return buildDiskStorageCache(diskCacheConfig, mDiskStorageFactory.get(diskCacheConfig));
}
 
Example #29
Source File: DiskStorageCacheFactory.java    From fresco with MIT License 4 votes vote down vote up
public static DiskStorageCache buildDiskStorageCache(
    DiskCacheConfig diskCacheConfig, DiskStorage diskStorage) {
  return buildDiskStorageCache(diskCacheConfig, diskStorage, Executors.newSingleThreadExecutor());
}
 
Example #30
Source File: ImagePipelineConfig.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
public DiskCacheConfig getMainDiskCacheConfig() {
  return mMainDiskCacheConfig;
}