Package com.squareup.okhttp
Class AndroidShimResponseCache
- java.lang.Object
-
- java.net.ResponseCache
-
- com.squareup.okhttp.AndroidShimResponseCache
-
public class AndroidShimResponseCache extends ResponseCache
A class provided for use by Android so that it can continue supporting aResponseCachewith stats.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Uninstalls the cache and releases any active resources.static AndroidShimResponseCachecreate(File directory, long maxSize)voiddelete()Uninstalls the cache and deletes all of its stored contents.voidflush()Force buffered operations to the filesystem.CacheResponseget(URI uri, String requestMethod, Map<String,List<String>> requestHeaders)Returns the cached response corresponding to the given request.CachegetCache()intgetHitCount()Returns the number of HTTP requests whose response was provided by the cache.intgetNetworkCount()Returns the number of HTTP requests that required the network to either supply a response or validate a locally cached response.intgetRequestCount()Returns the total number of HTTP requests that were made.booleanisEquivalent(File directory, long maxSize)longmaxSize()Returns the maximum number of bytes that this cache should use to store its data.CacheRequestput(URI uri, URLConnection urlConnection)Allows the protocol handler to cache data after retrieving resources.longsize()Returns the number of bytes currently being used to store the values in this cache.-
Methods inherited from class java.net.ResponseCache
getDefault, setDefault
-
-
-
-
Method Detail
-
create
public static AndroidShimResponseCache create(File directory, long maxSize) throws IOException
- Throws:
IOException
-
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:ResponseCacheReturns the cached response corresponding to the given request.- Specified by:
getin classResponseCache- Parameters:
uri- the request URI.requestMethod- the request method.requestHeaders- a map of request headers.- Returns:
- the
CacheResponseobject if the request is available in the cache ornullotherwise. - 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:ResponseCacheAllows the protocol handler to cache data after retrieving resources. TheResponseCachedecides whether the resource data should be cached or not. If so, this method returns aCacheRequestto write the resource data to. Otherwise, this method returnsnull.- Specified by:
putin classResponseCache- 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,
nullotherwise. - Throws:
IOException- if an I/O error occurs while adding the resource.
-
size
public long size() throws IOExceptionReturns the number of bytes currently being used to store the values in this cache. This may be greater than themaxSize()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 IOExceptionForce 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 conditionalGETrequests 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 IOExceptionUninstalls the cache and releases any active resources. Stored contents will remain on the filesystem.- Throws:
IOException
-
delete
public void delete() throws IOExceptionUninstalls the cache and deletes all of its stored contents.- Throws:
IOException
-
-