Glide Image 请求:downloadOnly 是否仅在下载前检查缓存?

Glide Image request : Does downloadOnly check the cache before downloading only?

我正在发出如下请求,但我想知道 downloadOnly 是否首先检查图片的缓存?

FutureTarget<File> future = Glide.with(applicationContext)
    .load(yourUrl)
    .downloadOnly(500, 500);
File cacheFile = future.get();

我的主要问题是 yourUrl 中的图像已经加载到缓存中,我需要一种同步方式在后台线程中从缓存中检索图像。

上面的代码有效,但我需要知道在downloadOnly之前是否有缓存检查。谢谢

在为 Glide 开启详细日志记录后,我能够准确地看到调用图像时发生了什么,而 DecodeJob 主要在不到 10 毫秒的时间内从缓存中获取数据,有时它会再次获取数据,而不是当然可能来自磁盘或网络。

所以最终我不得不只使用自定义 StreamModelLoader 检查缓存,如果尝试通过网络会抛出异常,然后在缓存 MISS 上使用默认流。

private final StreamModelLoader<String> cacheOnlyStreamLoader = new StreamModelLoader<String>() {
        @Override
        public DataFetcher<InputStream> getResourceFetcher(final String model, int i, int i1) {
            return new DataFetcher<InputStream>() {
                @Override
                public InputStream loadData(Priority priority) throws Exception {
                    throw new IOException();
                }

                @Override
                public void cleanup() {

                }

                @Override
                public String getId() {
                    return model;
                }

                @Override
                public void cancel() {

                }
            };
        }
    };

FutureTarget<File> future = Glide.with(progressBar.getContext())
                    .using(cacheOnlyStreamLoader)
                    .load(url).downloadOnly(width, height);

            File cacheFile = null;
            try {
                cacheFile = future.get();
            } catch(Exception ex) {
                ex.printStackTrace();  //exception thrown if image not in cache
            }

            if(cacheFile == null || cacheFile.length() < 1) {
                //didn't find the image in cache
                future = Glide.with(progressBar.getContext())
                        .load(url).downloadOnly(width, height);

                cacheFile = future.get(3, TimeUnit.SECONDS); //wait 3 seconds to retrieve the image
            }