/**
   * Check the cache for the current URL, and load it if it is valid.
   *
   * @param headers for the request
   * @return true if cached response is used.
   */
  boolean checkCache(Map<String, String> headers) {
    // Get the cache file name for the current URL
    CacheResult result = CacheManager.getCacheFile(url(), headers);

    if (result != null) {
      CacheLoader cacheLoader = new CacheLoader(this, result);

      // If I got a cachedUrl and the revalidation header was not
      // added, then the cached content valid, we should use it.
      if (!headers.containsKey(CacheManager.HEADER_KEY_IFNONEMATCH)
          && !headers.containsKey(CacheManager.HEADER_KEY_IFMODIFIEDSINCE)) {
        if (Config.LOGV) {
          Log.v(LOGTAG, "FrameLoader: HTTP URL in cache " + "and usable: " + url());
        }
        // Load the cached file
        cacheLoader.load();
        return true;
      } else {
        // The contents of the cache need to be revalidated
        // so just provide the listener with the cache loader
        // in the case that the server response positively to
        // the cached content.
        setCacheLoader(cacheLoader);
      }
    }
    return false;
  }
예제 #2
0
 /*
  * This function is used by handleUrlInterecpt and handleCache to
  * setup a load from the byte stream in a CacheResult.
  */
 private void startCacheLoad(CacheResult result) {
   if (WebView.LOGV_ENABLED) {
     Log.v(LOGTAG, "FrameLoader: loading from cache: " + mListener.url());
   }
   // Tell the Listener respond with the cache file
   CacheLoader cacheLoader = new CacheLoader(mListener, result);
   mListener.setCacheLoader(cacheLoader);
   cacheLoader.load();
 }