Package java.net
Class ResponseCache
- java.lang.Object
-
- java.net.ResponseCache
-
- Direct Known Subclasses:
AndroidShimResponseCache
public abstract class ResponseCache extends Object
CachesURLConnectionresponses.The system's default cache can be set using
setDefault(java.net.ResponseCache). IfURLConnection.getUseCaches()returns true,URLConnectionwill use the default response cache, if one has been set.Although
URLConnectionwill always callput(java.net.URI, java.net.URLConnection), the specificResponseCacheimplementation gets to decide what will actually be cached, and for how long.
-
-
Constructor Summary
Constructors Constructor Description ResponseCache()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract CacheResponseget(URI uri, String requestMethod, Map<String,List<String>> requestHeaders)Returns the cached response corresponding to the given request.static ResponseCachegetDefault()Returns the system's default response cache, or null.abstract CacheRequestput(URI uri, URLConnection connection)Allows the protocol handler to cache data after retrieving resources.static voidsetDefault(ResponseCache responseCache)Sets the system's default response cache.
-
-
-
Method Detail
-
getDefault
public static ResponseCache getDefault()
Returns the system's default response cache, or null.
-
setDefault
public static void setDefault(ResponseCache responseCache)
Sets the system's default response cache. Use null to remove the response cache.
-
get
public abstract CacheResponse get(URI uri, String requestMethod, Map<String,List<String>> requestHeaders) throws IOException
Returns the cached response corresponding to the given request.- 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.IllegalArgumentException- if any one of the parameters is set tonull.
-
put
public abstract CacheRequest put(URI uri, URLConnection connection) throws IOException
Allows 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.- Parameters:
uri- the reference to the requested resource.connection- 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.IllegalArgumentException- if any one of the parameters is set tonull.
-
-