Class AndroidShimResponseCache


  • public class AndroidShimResponseCache
    extends ResponseCache
    A class provided for use by Android so that it can continue supporting a ResponseCache with stats.
    • Method Detail

      • isEquivalent

        public boolean isEquivalent​(File directory,
                                    long maxSize)
      • getCache

        public Cache getCache()
      • get

        public CacheResponse get​(URI uri,
                                 String requestMethod,
                                 Map<String,​List<String>> requestHeaders)
                          throws IOException
        Description copied from class: ResponseCache
        Returns the cached response corresponding to the given request.
        Specified by:
        get in class ResponseCache
        Parameters:
        uri - the request URI.
        requestMethod - the request method.
        requestHeaders - a map of request headers.
        Returns:
        the CacheResponse object if the request is available in the cache or null otherwise.
        Throws:
        IOException - if an I/O error occurs while getting the cached data.
      • put

        public CacheRequest put​(URI uri,
                                URLConnection urlConnection)
                         throws IOException
        Description copied from class: ResponseCache
        Allows the protocol handler to cache data after retrieving resources. The ResponseCache decides whether the resource data should be cached or not. If so, this method returns a CacheRequest to write the resource data to. Otherwise, this method returns null.
        Specified by:
        put in class ResponseCache
        Parameters:
        uri - the reference to the requested resource.
        urlConnection - the connection to fetch the response.
        Returns:
        a CacheRequest object with a WriteableByteChannel if the resource has to be cached, null otherwise.
        Throws:
        IOException - if an I/O error occurs while adding the resource.
      • size

        public long size()
                  throws IOException
        Returns the number of bytes currently being used to store the values in this cache. This may be greater than the maxSize() if a background deletion is pending.
        Throws:
        IOException
      • maxSize

        public long maxSize()
        Returns the maximum number of bytes that this cache should use to store its data.
      • flush

        public void flush()
                   throws IOException
        Force buffered operations to the filesystem. This ensures that responses written to the cache will be available the next time the cache is opened, even if this process is killed.
        Throws:
        IOException
      • getNetworkCount

        public int getNetworkCount()
        Returns the number of HTTP requests that required the network to either supply a response or validate a locally cached response.
      • getHitCount

        public int getHitCount()
        Returns the number of HTTP requests whose response was provided by the cache. This may include conditional GET requests that were validated over the network.
      • getRequestCount

        public int getRequestCount()
        Returns the total number of HTTP requests that were made. This includes both client requests and requests that were made on the client's behalf to handle a redirects and retries.
      • close

        public void close()
                   throws IOException
        Uninstalls the cache and releases any active resources. Stored contents will remain on the filesystem.
        Throws:
        IOException
      • delete

        public void delete()
                    throws IOException
        Uninstalls the cache and deletes all of its stored contents.
        Throws:
        IOException