com.bumptech.glide.disklrucache.DiskLruCache Java Examples
The following examples show how to use
com.bumptech.glide.disklrucache.DiskLruCache.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DiskLruCacheWrapper.java From giffun with Apache License 2.0 | 6 votes |
@Override public File get(Key key) { String safeKey = safeKeyGenerator.getSafeKey(key); File result = null; try { //It is possible that the there will be a put in between these two gets. If so that shouldn't be a problem //because we will always put the same value at the same key so our input streams will still represent //the same data final DiskLruCache.Value value = getDiskCache().get(safeKey); if (value != null) { result = value.getFile(0); } } catch (IOException e) { if (Log.isLoggable(TAG, Log.WARN)) { Log.w(TAG, "Unable to get from disk cache", e); } } return result; }
Example #2
Source File: DiskLruCacheWrapper.java From giffun with Apache License 2.0 | 6 votes |
@Override public void put(Key key, Writer writer) { String safeKey = safeKeyGenerator.getSafeKey(key); writeLocker.acquire(key); try { DiskLruCache.Editor editor = getDiskCache().edit(safeKey); // Editor will be null if there are two concurrent puts. In the worst case we will just silently fail. if (editor != null) { try { File file = editor.getFile(0); if (writer.write(file)) { editor.commit(); } } finally { editor.abortUnlessCommitted(); } } } catch (IOException e) { if (Log.isLoggable(TAG, Log.WARN)) { Log.w(TAG, "Unable to put to disk cache", e); } } finally { writeLocker.release(key); } }
Example #3
Source File: ImageLoader.java From imsdk-android with MIT License | 6 votes |
/** * 获取是否有某张原图的缓存 * 缓存模式必须是:DiskCacheStrategy.SOURCE 才能获取到缓存文件 */ public static File getGlideCacheFile(Context context, String url) { try { url = QtalkStringUtils.findRealUrl(url); OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain()); SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator(); String safeKey = safeKeyGenerator.getSafeKey(originalKey); File file = new File(context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR); DiskLruCache diskLruCache = DiskLruCache.open(file, 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE); DiskLruCache.Value value = diskLruCache.get(safeKey); if (value != null) { return value.getFile(0); } } catch (Exception e) { e.printStackTrace(); } return null; }
Example #4
Source File: GlideLoader.java From ImageLoader with Apache License 2.0 | 6 votes |
/** * 无法同步判断 * 参见:https://github.com/bumptech/glide/issues/639 * * 4.0以上可用: * val file: File? = try { Glide.with(view.context).downloadOnly().load(url).apply(RequestOptions().onlyRetrieveFromCache(true)).submit().get() } catch (e: Exception) { e.printStackTrace() null } *https://github.com/bumptech/glide/issues/2972 * * @param url * @return */ @Override public boolean isCached(String url) { OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain()); SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator(); String safeKey = safeKeyGenerator.getSafeKey(originalKey); try { DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE); DiskLruCache.Value value = diskLruCache.get(safeKey); if (value != null && value.getFile(0).exists() && value.getFile(0).length() > 30) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #5
Source File: Glide4Loader.java From ImageLoader with Apache License 2.0 | 6 votes |
/** * 无法同步判断 * 参见:https://github.com/bumptech/glide/issues/639 * * 4.0以上可用: * val file: File? = try { Glide.with(view.context).downloadOnly().load(url).apply(RequestOptions().onlyRetrieveFromCache(true)).submit().get() } catch (e: Exception) { e.printStackTrace() null } *https://github.com/bumptech/glide/issues/2972 * * @param url * @return */ @Override public boolean isCached(String url) { OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain()); SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator(); String safeKey = safeKeyGenerator.getSafeKey(originalKey); try { DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE); DiskLruCache.Value value = diskLruCache.get(safeKey); if (value != null && value.getFile(0).exists() && value.getFile(0).length() > 30) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #6
Source File: GlideLoader.java From ImageLoader with Apache License 2.0 | 5 votes |
public File getCacheFile(String url) { OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain()); SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator(); String safeKey = safeKeyGenerator.getSafeKey(originalKey); try { DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE); DiskLruCache.Value value = diskLruCache.get(safeKey); if (value != null) { return value.getFile(0); } } catch (IOException e) { e.printStackTrace(); } return null; }
Example #7
Source File: Glide4Loader.java From ImageLoader with Apache License 2.0 | 5 votes |
public File getCacheFile(String url) { OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain()); SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator(); String safeKey = safeKeyGenerator.getSafeKey(originalKey); try { DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE); DiskLruCache.Value value = diskLruCache.get(safeKey); if (value != null) { return value.getFile(0); } } catch (IOException e) { e.printStackTrace(); } return null; }
Example #8
Source File: DiskLruCacheWrapper.java From giffun with Apache License 2.0 | 4 votes |
public synchronized DiskLruCache getDiskCache() throws IOException { if (diskLruCache == null) { diskLruCache = DiskLruCache.open(directory, APP_VERSION, VALUE_COUNT, maxSize); } return diskLruCache; }