public abstract class ResponseCache extends Object
URLConnection
responses.
The system's default cache can be set using setDefault(java.net.ResponseCache)
.
If URLConnection.getUseCaches()
returns true, URLConnection
will use the
default response cache, if one has been set.
Although URLConnection
will always call put(java.net.URI, java.net.URLConnection)
, the specific
ResponseCache
implementation gets to decide what will actually be cached,
and for how long.
Constructor and Description |
---|
ResponseCache() |
Modifier and Type | Method and Description |
---|---|
abstract CacheResponse |
get(URI uri,
String requestMethod,
Map<String,List<String>> requestHeaders)
Returns the cached response corresponding to the given request.
|
static ResponseCache |
getDefault()
Returns the system's default response cache, or null.
|
abstract CacheRequest |
put(URI uri,
URLConnection connection)
Allows the protocol handler to cache data after retrieving resources.
|
static void |
setDefault(ResponseCache responseCache)
Sets the system's default response cache.
|
public static ResponseCache getDefault()
public static void setDefault(ResponseCache responseCache)
public abstract CacheResponse get(URI uri, String requestMethod, Map<String,List<String>> requestHeaders) throws IOException
uri
- the request URI.requestMethod
- the request method.requestHeaders
- a map of request headers.CacheResponse
object if the request is available in the cache
or null
otherwise.IOException
- if an I/O error occurs while getting the cached data.IllegalArgumentException
- if any one of the parameters is set to null
.public abstract CacheRequest put(URI uri, URLConnection connection) throws IOException
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
.uri
- the reference to the requested resource.connection
- the connection to fetch the response.null
otherwise.IOException
- if an I/O error occurs while adding the resource.IllegalArgumentException
- if any one of the parameters is set to null
.