public void clearDiskCache(String uri) { synchronized (mDiskCacheLock) { if (mDiskLruCache != null && !mDiskLruCache.isClosed()) { try { mDiskLruCache.remove(uri); } catch (Throwable e) { LogUtils.e(e.getMessage(), e); } } } }
/** * Closes the disk cache associated with this ImageCache object. Note that this includes disk * access so this should not be executed on the main/UI thread. */ public void close() { synchronized (mDiskCacheLock) { if (mDiskLruCache != null) { try { if (!mDiskLruCache.isClosed()) { mDiskLruCache.close(); mDiskLruCache = null; } } catch (Throwable e) { LogUtils.e(e.getMessage(), e); } } } }
public void clearDiskCache() { synchronized (mDiskCacheLock) { if (mDiskLruCache != null && !mDiskLruCache.isClosed()) { try { mDiskLruCache.delete(); } catch (Throwable e) { LogUtils.e(e.getMessage(), e); } mDiskLruCache = null; isDiskCacheReadied = false; } } initDiskCache(); }
/** * 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(); } }