/** * 设置缓存设置 */ private void customCacheOptions(Context context, GlideBuilder builder) { //设置内存缓存大小和bitmap池大小 MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context) .setMemoryCacheScreens(2) .build(); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapCacheSize = calculator.getBitmapPoolSize(); //比默认的内存分配大20% int customMemoryCacheSize = (int) (4 * defaultMemoryCacheSize); int customBitmapPoolSize = (int) (4 * defaultBitmapCacheSize); builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); //设置磁盘缓存 int cacheSize100MegaBytes = 1024 * 1024 * 100;//200M //外部磁盘缓存 builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); }
/** * Lazily apply options to a {@link GlideBuilder} immediately before the Glide singleton is * created. * <p> * <p> * This method will be called once and only once per implementation. * </p> * * @param context An Application {@link Context}. * @param builder The {@link GlideBuilder} that will be used to create Glide. */ @Override public void applyOptions(Context context, GlideBuilder builder) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); MemorySizeCalculator calculator = new MemorySizeCalculator(context); // Increasing cache & pool by 25% - default is 250MB int memoryCacheSize = (int) (1.25 * calculator.getMemoryCacheSize()); int bitmapPoolSize = (int) (1.25 * calculator.getBitmapPoolSize()); int storageCacheSize = 1024 * 1024 * 350; if(context.getExternalCacheDir() != null) { long total = context.getExternalCacheDir().getUsableSpace(); storageCacheSize = (int) (total*0.14); } builder.setMemoryCache(new LruResourceCache(memoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(bitmapPoolSize)); builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, storageCacheSize)); builder.setDecodeFormat(ActivityManagerCompat.isLowRamDevice(activityManager) ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888); }
@Override public void applyOptions(Context context, GlideBuilder builder) { ViewTarget.setTagId(R.id.glide_tag_id); // Apply options to the builder here. // 默认内存和图片池大小 // MemorySizeCalculator calculator = new MemorySizeCalculator(context); // int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); // 默认内存大小 // int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); // 默认图片池大小 // builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize)); // 该两句无需设置,是默认的 // builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize)); //定义图片的本地磁盘缓存 // File cacheDir = context.getExternalCacheDir();//指定的是数据的缓存地址 // int diskCacheSize = 1024 * 1024 * 1024;//最多可以缓存多少字节的数据 //设置磁盘缓存大小 // builder.setDiskCache(new DiskLruCacheFactory(cacheDir.getPath(), "glide", diskCacheSize)); // 定义缓存大小和位置 if (BaseConfig.sSDCardExist) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, extDiskSize)); //外部存储 } else { builder.setDiskCache(new InternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, intDiskSize)); //内部存储 } // 自定义内存和图片池大小 // builder.setMemoryCache(new LruResourceCache(memorySize)); // builder.setBitmapPool(new LruBitmapPool(memorySize)); // builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); }
@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); } }); }
/** * 清除图片所有缓存 */ public void clearImageAllCache(Context context) { clearImageDiskCache(context); clearImageMemoryCache(context); String ImageExternalCatchDir=context.getExternalCacheDir()+ ExternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR; deleteFolderFile(ImageExternalCatchDir, true); }
@Override public void applyOptions(Context context, GlideBuilder builder) { // builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); if (AppUtil.hasSDCard()) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "GlideCache", 500 * 1024 * 1024)); LogUtil.e("Glide使用SD卡缓存"); } else { builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "GlideCache", 250 * 1024 * 1024)); LogUtil.e("Glide使用内部缓存"); } builder.setMemoryCache(new LruResourceCache(100 * 1024 * 1024)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { final int cacheSize250M = 262144000;// glide默认磁盘缓存大小为250m builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "pic_cache", cacheSize250M)); // 默认内存缓存为两个屏幕像素字节大小w*h*4*2 // 设置默认的请求选项 }
@Override public void applyOptions(final Context context, final GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 1024 * 1024 * 500)); MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build(); 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)); }
/** * 清除图片所有缓存 */ public void clearImageAllCache(Context context) { clearImageDiskCache(context); clearImageMemoryCache(context); String ImageExternalCatchDir=context.getExternalCacheDir()+ExternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR; deleteFolderFile(ImageExternalCatchDir, true); }
@Override public void applyOptions(Context context, GlideBuilder builder) { // 定义缓存大小和位置 builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskSize)); // 内存中 builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "cache", diskSize)); // sd卡中 // 自定义内存和图片池大小 builder.setMemoryCache(new LruResourceCache(memorySize)); // 自定义内存大小 builder.setBitmapPool(new LruBitmapPool(memorySize)); // 自定义图片池大小 // 定义图片格式 builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); // 高质量 // builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // 默认(中等质量) }
/** * 清除图片所有缓存 */ public void clearImageAllCache(Context context) { clearImageDiskCache(context); clearImageMemoryCache(context); String ImageExternalCatchDir = context.getExternalCacheDir() + ExternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR; deleteFolderFile(ImageExternalCatchDir, true); }
/** * 清除图片所有缓存 */ public static void clearImageAllCache(Context context) { clearImageDiskCache(context); clearImageMemoryCache(context); String ImageExternalCatchDir = context.getExternalCacheDir() + ExternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR; deleteFolderFile(ImageExternalCatchDir, true); }
/** * ************************ GlideModule override ************************ */ @Override public void applyOptions(Context context, GlideBuilder builder) { // sdcard/Android/data/com.netease.nim.demo/glide final String cachedDirName = "glide"; builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, cachedDirName, MAX_DISK_CACHE_SIZE)); LogUtil.i(TAG, "NIMGlideModule apply options, disk cached path=" + context.getExternalCacheDir() + File.pathSeparator + cachedDirName); }
@Override public void applyOptions(Context context, GlideBuilder gb) { String cacheSizeStr = HiSettingsHelper.getInstance().getStringValue(HiSettingsHelper.PERF_CACHE_SIZE_IN_MB, DEFAULT_CACHE_SIZE + ""); int cacheSize = DEFAULT_CACHE_SIZE; if (TextUtils.isDigitsOnly(cacheSizeStr)) { cacheSize = Integer.parseInt(cacheSizeStr); if (cacheSize < MIN_CACHE_SIZE) { cacheSize = DEFAULT_CACHE_SIZE; } } gb.setDiskCache(new ExternalCacheDiskCacheFactory(context, cacheSize * 1024 * 1024)); GlideHelper.initDefaultFiles(); }
@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 ) ); }
@Override public void applyOptions(Context context, GlideBuilder builder) { int MEM_CACHE_SIZE = 1024 * 1024 * ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass() / 3; builder.setMemoryCache(new LruResourceCache(MEM_CACHE_SIZE)); builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); builder.setDiskCache(new ExternalCacheDiskCacheFactory(context)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { int diskCacheSizeBytes = 1024 * 1024 * 16; builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, diskCacheSizeBytes)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setMemoryCache(new LruResourceCache(10 * M)); builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "glide-cache", DEFAULT_DISK_CACHE_SIZE)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "GlideCache", DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { // just so it's easier to access the cache (public) builder.setDiskCache(new ExternalCacheDiskCacheFactory(context)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context)); }
@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)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "cache", DISK_CACHE_SIZE)) .setMemoryCache(new LruResourceCache(cacheSize)); }
@Override public void applyOptions(final Context context, GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 1024 * 1024 * 500)); }