当前位置: 首页>>代码示例>>Java>>正文


Java DiskCache类代码示例

本文整理汇总了Java中com.bumptech.glide.load.engine.cache.DiskCache的典型用法代码示例。如果您正苦于以下问题:Java DiskCache类的具体用法?Java DiskCache怎么用?Java DiskCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DiskCache类属于com.bumptech.glide.load.engine.cache包,在下文中一共展示了DiskCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            File cacheDirectory = new File(DataHelper.getCacheFile(UiUtils.getContext()), "Glide");
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(cacheDirectory), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    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));

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:GlideConfiguration.java

示例2: Engine

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
public Engine(MemoryCache memoryCache,
    DiskCache.Factory diskCacheFactory,
    GlideExecutor diskCacheExecutor,
    GlideExecutor sourceExecutor,
    GlideExecutor sourceUnlimitedExecutor,
    GlideExecutor animationExecutor) {
  this(
      memoryCache,
      diskCacheFactory,
      diskCacheExecutor,
      sourceExecutor,
      sourceUnlimitedExecutor,
      animationExecutor,
      /*jobs=*/ null,
      /*keyFactory=*/ null,
      /*activeResources=*/ null,
      /*engineJobFactory=*/ null,
      /*decodeJobFactory=*/ null,
      /*resourceRecycler=*/ null);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:Engine.java

示例3: getEngine

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
Engine getEngine() {
  if (engine == null) {
    engine =
        new Engine(
            cache,
            mock(DiskCache.Factory.class),
            GlideExecutor.newDiskCacheExecutor(),
            MockGlideExecutor.newMainThreadExecutor(),
            MockGlideExecutor.newMainThreadExecutor(),
            MockGlideExecutor.newMainThreadExecutor(),
            jobs,
            keyFactory,
            activeResources,
            engineJobFactory,
            decodeJobFactory,
            resourceRecycler);
  }
  return engine;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:EngineTest.java

示例4: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.getCacheFile(UiUtils.getContext()), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    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));

}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:22,代码来源:GlideConfiguration.java

示例5: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void applyOptions(final Context context, GlideBuilder builder) {

    // 缓存目录
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            AppComponent component = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(FileUtils.makeDirs(new File(component.cacheFile(), "Glide")), DISK_SIZE);
        }
    });

    // 自定义内存缓存和图片池大小
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    builder.setMemoryCache(new LruResourceCache((int) (1.2 * calculator.getMemoryCacheSize())));
    builder.setBitmapPool(new LruBitmapPool((int) (1.2 * calculator.getBitmapPoolSize())));

    // 图片格式
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // 默认
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:22,代码来源:GlideConfiguration.java

示例6: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(Glide.getPhotoCacheDir(context), ConfigConstants.MAX_DISK_CACHE_SIZE);
        }
    });

    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));

}
 
开发者ID:VK2012,项目名称:AppCommonFrame,代码行数:22,代码来源:GlideConfiguration.java

示例7: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override public void applyOptions(final Context context, GlideBuilder builder) {
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                File cacheLocation = new File(AppUtils.getPath(context, AppUtils.StorageFile.cache));
                cacheLocation.mkdirs();
                return DiskLruCacheWrapper.get(cacheLocation, DISK_CACHE_SIZE);
            }
        });
//        MemorySizeCalculator calculator = new MemorySizeCalculator(context);
//        int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
//        int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
//
//        int customMemoryCacheSize = (int) (0.25 * defaultMemoryCacheSize);
//        int customBitmapPoolSize = (int) (0.25* defaultBitmapPoolSize);
//
//        builder.setMemoryCache( new LruResourceCache( customMemoryCacheSize ));
//        builder.setBitmapPool( new LruBitmapPool( customBitmapPoolSize ));
    }
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:20,代码来源:CustomCachingGlideModule.java

示例8: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    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));

}
 
开发者ID:yangxp108,项目名称:MVPArms_Fragment-fragment,代码行数:23,代码来源:GlideConfiguration.java

示例9: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File pathIcons = new File(Configuration.PATH_CACHE_ICONS);
            pathIcons.mkdirs();
            return DiskLruCacheWrapper.get(pathIcons, DEFAULT_DISK_CACHE_SIZE);
        }
    });

    final MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    final int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize / 2));
    final int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize / 2));
}
 
开发者ID:Aptoide,项目名称:aptoide-client,代码行数:18,代码来源:AptoideGlideModule.java

示例10: init

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
public static void init(final Context context) {
        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setReadTimeout(30, TimeUnit.SECONDS);
        okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS);
//        okHttpClient.setProtocols(Arrays.asList(Protocol.HTTP_1_1));

        GlideBuilder glideBuilder = new GlideBuilder(context)
                .setDiskCache(new DiskCache.Factory() {
                    @Override
                    public DiskCache build() {
                        // Careful: the external cache directory doesn't enforce permissions
                        File cacheLocation = new File(context.getExternalCacheDir(), AppConfig.CACHE_IMAGE_DIR);
                        cacheLocation.mkdirs();
                        return DiskLruCacheWrapper.get(cacheLocation, 100 * 1024 * 1024);
                    }
                });
        if (!Glide.isSetup()) {
            Glide.setup(glideBuilder);
        }

        Glide.get(context).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient));
    }
 
开发者ID:BigAppOS,项目名称:BigApp_Discuz_Android,代码行数:23,代码来源:GlideUtils.java

示例11: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 设置格式
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    // 缓存到data目录下最大50M
    // 缓存目录为程序内部缓存目录
    // /data/data/your_package_name/image_manager_disk_cache/
    // (不能被其它应用访问)且缓存最大为250MB
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
            DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
            DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 缓存到外部磁盘SD卡上,字节
    // builder.setDiskCache(new ExternalCacheDiskCacheFactory(
    // context,DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
    // DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 设置内存缓存大小
    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));
}
 
开发者ID:leibing8912,项目名称:ImageSwitcher,代码行数:25,代码来源:CustomGlideModule.java

示例12: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@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);
        }
    });

}
 
开发者ID:dalingge,项目名称:GankGirl,代码行数:26,代码来源:GlideConfiguration.java

示例13: put

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
public void put(final String key, final Entry entry) {
    diskCache.put(new StringKey(key), new DiskCache.Writer() {
        @Override
        public boolean write(OutputStream os) {
            CacheHeader header = new CacheHeader(key, entry);
            boolean success = header.writeHeader(os);
            if (success) {
                try {
                    os.write(entry.data);
                } catch (IOException e) {
                    success = false;
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Unable to write data", e);
                    }
                }
            }
            return success;
        }
    });
}
 
开发者ID:The-WebOps-Club,项目名称:saarang-iosched,代码行数:22,代码来源:VolleyDiskCacheWrapper.java

示例14: applyOptions

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
@Override
    public void applyOptions(final Context context, GlideBuilder builder) {
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                File dir = CacheUtil.getCacheDir(context, "glide/1");
                return DiskLruCacheWrapper.get(dir, 50 * 1024 * 1024);
            }
        });
        //blows up
//        RequestOptions options = new RequestOptions()
//                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
//                .centerCrop(context)
//                .placeholder(R.drawable.default_artwork)
//                ;
//        builder.setDefaultRequestOptions(options);
        if (BuildConfig.LOGVV) {
            builder.setLogLevel(Log.DEBUG);
        }
    }
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:21,代码来源:ArtworkGlideModule.java

示例15: Engine

import com.bumptech.glide.load.engine.cache.DiskCache; //导入依赖的package包/类
public Engine(MemoryCache memoryCache,
    DiskCache.Factory diskCacheFactory,
    GlideExecutor diskCacheExecutor,
    GlideExecutor sourceExecutor,
    GlideExecutor sourceUnlimitedExecutor) {
  this(memoryCache, diskCacheFactory, diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor,
      null, null, null, null, null, null);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Engine.java


注:本文中的com.bumptech.glide.load.engine.cache.DiskCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。