/** * customize cache * * @param context * @param memoryCacheSizeInKB How many memory should use. Will not be greater than 50% of free * memory * @param defaultDiskCachePath Default image cache path. Absolute path or a relative path under * cache directory. External cache first. If not specified, using {@link * #DEFAULT_FILE_CACHE_DIR} under cache directory. * @param defaultDiskCacheSizeInKB Default disk cache size. * @param stableDiskCachePath Path for stable cache directory. Default is {@link * #STABLE_FILE_CACHE_DIR} * @param stableDiskCacheSizeInKB Stable disk cache size. */ public static void customizeCache( Context context, int memoryCacheSizeInKB, String defaultDiskCachePath, int defaultDiskCacheSizeInKB, String stableDiskCachePath, int stableDiskCacheSizeInKB) { // init memory cache first if (memoryCacheSizeInKB > 0) { int maxCacheSizeInKB = Math.round(0.5f * Runtime.getRuntime().maxMemory() / 1024); memoryCacheSizeInKB = Math.min(memoryCacheSizeInKB, maxCacheSizeInKB); sDefaultImageMemoryCache = new DefaultMemoryCache(memoryCacheSizeInKB); } if (defaultDiskCacheSizeInKB > 0 && !TextUtils.isEmpty(defaultDiskCachePath)) { ImageDiskCacheProvider imageFileProvider = getImageFileProvider( context, defaultDiskCachePath, defaultDiskCacheSizeInKB, DEFAULT_FILE_CACHE_DIR); if (imageFileProvider != null) { sDefaultImageProvider = new ImageProvider(context, getDefaultImageMemoryCache(), imageFileProvider); } } if (stableDiskCacheSizeInKB > 0 && !TextUtils.isEmpty(stableDiskCachePath)) { ImageDiskCacheProvider imageFileProvider = getImageFileProvider( context, stableDiskCachePath, stableDiskCacheSizeInKB, STABLE_FILE_CACHE_DIR); if (imageFileProvider != null) { sStableImageProvider = new ImageProvider(context, getDefaultImageMemoryCache(), imageFileProvider); } } }
public static int getDefaultMemoryCacheSizeInKB() { float percent = 0.2f; int memoryCacheSizeInKB = Math.round(percent * Runtime.getRuntime().maxMemory() / 1024); return memoryCacheSizeInKB; }