Java Code Examples for com.bumptech.glide.disklrucache.DiskLruCache#Value

The following examples show how to use com.bumptech.glide.disklrucache.DiskLruCache#Value . 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 vote down vote up
@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: ImageLoader.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 获取是否有某张原图的缓存
 * 缓存模式必须是: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 3
Source File: GlideLoader.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
/**
 * 无法同步判断
 * 参见: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 4
Source File: Glide4Loader.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
/**
 * 无法同步判断
 * 参见: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: GlideLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
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 6
Source File: Glide4Loader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
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;
}