Пример #1
0
 @Override
 public void clear() {
   try {
     cache.delete();
   } catch (IOException e) {
     L.e(e);
   }
   try {
     initCache(cache.getDirectory(), reserveCacheDir, cache.getMaxSize(), cache.getMaxFileCount());
   } catch (IOException e) {
     L.e(e);
   }
 }
Пример #2
0
 @Override
 public void close() {
   try {
     cache.close();
   } catch (IOException e) {
     L.e(e);
   }
   cache = null;
 }
Пример #3
0
 @Override
 public boolean remove(String imageUri) {
   try {
     return cache.remove(getKey(imageUri));
   } catch (IOException e) {
     L.e(e);
     return false;
   }
 }
Пример #4
0
 @Override
 public File get(String imageUri) {
   DiskLruCache.Snapshot snapshot = null;
   try {
     snapshot = cache.get(getKey(imageUri));
     return snapshot == null ? null : snapshot.getFile(0);
   } catch (IOException e) {
     L.e(e);
     return null;
   } finally {
     if (snapshot != null) {
       snapshot.close();
     }
   }
 }
Пример #5
0
 private void initCache(
     File cacheDir, File reserveCacheDir, long cacheMaxSize, int cacheMaxFileCount)
     throws IOException {
   try {
     cache = DiskLruCache.open(cacheDir, 1, 1, cacheMaxSize, cacheMaxFileCount);
   } catch (IOException e) {
     L.e(e);
     if (reserveCacheDir != null) {
       initCache(reserveCacheDir, null, cacheMaxSize, cacheMaxFileCount);
     }
     if (cache == null) {
       throw e; // new RuntimeException("Can't initialize disk cache", e);
     }
   }
 }