/** * Initializes the disk cache. Note that this includes disk access so this should not be executed * on the main/UI thread. By default an ImageCache does not initialize the disk cache when it is * created, instead you should call initDiskCache() to initialize it on a background thread. */ public void initDiskCache() { if (!globalConfig.isDiskCacheEnabled()) return; // Set up disk cache synchronized (mDiskCacheLock) { if (mDiskLruCache == null || mDiskLruCache.isClosed()) { File diskCacheDir = new File(globalConfig.getDiskCachePath()); if (diskCacheDir.exists() || diskCacheDir.mkdirs()) { long availableSpace = OtherUtils.getAvailableSpace(diskCacheDir); long diskCacheSize = globalConfig.getDiskCacheSize(); diskCacheSize = availableSpace > diskCacheSize ? diskCacheSize : availableSpace; try { mDiskLruCache = LruDiskCache.open(diskCacheDir, 1, 1, diskCacheSize); mDiskLruCache.setFileNameGenerator(globalConfig.getFileNameGenerator()); } catch (Throwable e) { mDiskLruCache = null; LogUtils.e(e.getMessage(), e); } } } isDiskCacheReadied = true; mDiskCacheLock.notifyAll(); } }