Java 类com.bumptech.glide.load.engine.cache.DiskLruCacheFactory 实例源码

项目:GlideDemo    文件:SimpleGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //定义缓存大小为100M
    int  diskCacheSize =  100 * 1024 * 1024;

    //自定义缓存 路径 和 缓存大小
    String diskCachePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/glideCache" ;

    //提高图片质量
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    //自定义磁盘缓存:这种缓存只有自己的app才能访问到
    // builder.setDiskCache( new InternalCacheDiskCacheFactory( context , diskCacheSize )) ;
    // builder.setDiskCache( new InternalCacheDiskCacheFactory( context , diskCachePath , diskCacheSize  )) ;

    //自定义磁盘缓存:这种缓存存在SD卡上,所有的应用都可以访问到
    builder.setDiskCache(new DiskLruCacheFactory( diskCachePath , diskCacheSize ));

}
项目:GankGirl    文件:GlideConfiguration.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);// Bitmap格式转换到ARGB_8888
    //内存缓存
    MemorySizeCalculator memorySizeCalculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = memorySizeCalculator.getMemoryCacheSize();
    int defalutBitmapPoolSize = memorySizeCalculator.getBitmapPoolSize();
    builder.setMemoryCache(new LruResourceCache((int) (defalutBitmapPoolSize * 1.2)));//内部
    builder.setBitmapPool(new LruBitmapPool((int) (defalutBitmapPoolSize * 1.2)));
    //磁盘缓存
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 1024 * 1024 * 10));//内部磁盘缓存
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 10 * 1024 * 1024));//磁盘缓存到外部存储
    //指定缓存目录1
    String downLoadPath = Environment.getDownloadCacheDirectory().getPath();
    builder.setDiskCache(new DiskLruCacheFactory(downLoadPath, defaultMemoryCacheSize));
    //指定缓存目录2
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File cacheLocation = new File(FileUtils.getCacheDir(context), "GlideCache");
            return DiskLruCacheWrapper.get(cacheLocation, 1024 * 1024 * 10);
        }
    });

}
项目:FriendCircle    文件:GlobalGlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //解决setTag问题
    ViewTarget.setTagId(R.id.glide_tag_id);
    //磁盘缓存
    builder.setDiskCache(new DiskLruCacheFactory(AppFileHelper.getAppCachePath(), 50 * 1024 * 1024));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    //内存缓存
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    //设置比默认大小大1.5倍的缓存和图片池大小
    int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize);
    int customBitmapPoolSize = defaultBitmapPoolSize;


    KLog.i("poolSize", "bitmapPoolSize >>>>>   "
            + android.text.format.Formatter.formatFileSize(context, customBitmapPoolSize)
            + "          memorySize>>>>>>>>   " +
            android.text.format.Formatter.formatFileSize(context, customMemoryCacheSize));

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:GankMeiZhi    文件:MyGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache( new LruResourceCache( customMemoryCacheSize ));
    builder.setBitmapPool( new LruBitmapPool( customBitmapPoolSize ));

    int cacheSize50MegaBytes = 52428800;

    /*builder.setDiskCache(
            new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)
    );*/

    /*builder.setDiskCache(
    new ExternalCacheDiskCacheFactory());*/
    builder.setDiskCache(new DiskLruCacheFactory(Constants.OwnCacheDirectory,"Cache",cacheSize50MegaBytes)) ;
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); //PREFER_RGB_565
}
项目:BandWith    文件:GlideCustomModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Apply options to the builder here.
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    int cacheSize100MegaBytes = 104857600;
    String downloadDirectoryPath = Environment.getDownloadCacheDirectory().getPath();
    builder.setDiskCache(
            new DiskLruCacheFactory(downloadDirectoryPath, cacheSize100MegaBytes)
    );
}
项目:Hitalk    文件:VideoListGlideModule.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter
            () {
        @Override
        public File getCacheDirectory() {
            return context.getExternalCacheDir();
        }
    }, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
}
项目:AndroidBase    文件:OkHttpGlideModule.java   
@Override
  public void applyOptions(Context context, GlideBuilder builder) {

//    int deskacheize = 1024 * 1024 * 30;
    int maxMemory = (int)Runtime.getRuntime().maxMemory();
    int memoryCheSize = maxMemory / 8;
//    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide", deskacheize));
    builder.setDiskCache(new DiskLruCacheFactory(FileUtil.getCacheDir(),"glide", DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    builder.setMemoryCache(new LruResourceCache(memoryCheSize));
    builder.setBitmapPool(new LruBitmapPool(memoryCheSize));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
  }
项目:VideoListPlayer    文件:VideoListGlideModule.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    ViewTarget.setTagId(R.id.glide_loader);
    builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter
            () {
        @Override
        public File getCacheDirectory() {
            return context.getExternalCacheDir();
        }
    }, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
}
项目:android-tutorials-glide    文件:CustomCachingGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    // memory cache
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    // disk cache
    // set size & external vs. internal
    int cacheSize100MegaBytes = 104857600;

    builder.setDiskCache(
            new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));

    builder.setDiskCache(
            new ExternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));

    // set custom location
    String downloadDirectoryPath = Environment.getDownloadCacheDirectory().getPath();

    builder.setDiskCache(
            new DiskLruCacheFactory(downloadDirectoryPath, cacheSize100MegaBytes));

    // In case you want to specify a cache folder ("glide"):
    //builder.setDiskCache(
    //        new DiskLruCacheFactory( downloadDirectoryPath, "glidecache", cacheSize100MegaBytes ) );

}
项目:QxGradleConfig    文件:GlideConfiguration.java   
@Override
    public void applyOptions(Context context, GlideBuilder builder) {
        // Apply options to the builder here.
//        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
        builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); //默认的

        final int size = 1024 * 1024 * 50;

        builder.setDiskCache(
                new InternalCacheDiskCacheFactory(context, size));
        builder.setDiskCache(
                new InternalCacheDiskCacheFactory(context, "pics", size));//内部缓存目录
        builder.setDiskCache(
                new ExternalCacheDiskCacheFactory(context, "outpics", size));//外部sdcard缓存目录

        // If you can figure out the folder without I/O:
// Calling Context and Environment class methods usually do I/O.
        builder.setDiskCache(
                new DiskLruCacheFactory("diskCacheFolder", size)); //指定sdcard缓存目录

// In case you want to specify a cache folder ("glide"):
        builder.setDiskCache(
                new DiskLruCacheFactory("diskCacheFolder_glide", "diskCacheName", size));//sdcard缓存目录

// In case you need to query the file system while determining the folder:
        GlideBuilder diskCacheFolder = builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter() {
            @Override
            public File getCacheDirectory() {
                return new File("diskCacheFolder");
            }
        }, size));


        builder.setDiskCache(new DiskCache.Factory() {
            @Override public DiskCache build() {
                File cacheLocation = new File("diskCacheFolder");
                if (!cacheLocation.exists())
                    cacheLocation.mkdirs();
                return DiskLruCacheWrapper.get(cacheLocation, size);
            }
        });


        //----------- memory cache  -------------
        builder.setMemoryCache(new LruResourceCache(size/10));

        //----------- bitmap pool  -------------
        builder.setBitmapPool(new LruBitmapPool(size/20));

    }