Volley CacheDispatcher 挂起

Volley CacheDispatcher hangs

我创建了自己的请求,并在构造函数中设置了 setShouldCache(Boolean.TRUE); .

第一次调用请求时(未使用缓存)一切正常,我可以看到正在缓存的内容。我第二次调用相同的 URL 一件奇怪的事情发生了:

else {
                // Insert 'null' queue for this cacheKey, indicating there is now a request in
                // flight.
                mWaitingRequests.put(cacheKey, null);
                mCacheQueue.add(request); <-- being called

摘自RequestQueue.add

我可以在调试器中看到 mCacheQueue 已填满,但没有从中调用任何内容,例如

// Take a request from the queue.
request = mCacheQueue.take();

摘自CacheDispatcher.run

卡住了。

这是创建请求的代码片段:

  RequestFuture<String> future = _requestFutureProvider.get();
  FetchArticleImageRequest request = new FetchArticleImageRequest(pageId,
                            300,
                            future, future);
 _requestQueue.add(request);
 try {
         // this will never block
         imgUrl = future.get(3, TimeUnit.SECONDS);
 } catch (Exception e) {
         log.error("Unable to fetch img url", e);
 }

还有一条信息,我在另一个请求的 parseQueryResponse 中 运行 请求,所以它不会 运行 在主线程中。

顺便说一句,当不使用缓存时一切正常(例如,正在向服务器发出请求)。

知道这里发生了什么吗?

好的,发给google群里的小伙伴们(Ficus Kirkpatrick)有答案了。

它发生是因为我 运行 一个未来请求在另一个请求中 运行 作为缓存调度程序的一部分。我的解决方案是从分派其他请求的请求中删除缓存。