public abstract class

ResponseCache

extends Object
java.lang.Object
   ↳ java.net.ResponseCache

Class Overview

This class is an implementation of URLConnection caches intended primarily for the according stream handler implementations.

The system's default cache can be registered by invoking the method setDefault(ResponseCache) and be retrieved by invoking the method getDefault(). If URLConnection#useCaches is set, URLConnection class will use ResponseCache to store and get resources.

Whether the resource is cached depends on the implementation of ResponseCache. If so, a CacheResponse is returned from which the stream handler reads. If the stream handler fails to get a resource from the cache, it must get the resource from its original location.

To write to the cache, the protocol handlers call put(), upon which a CacheRequest is supplied to which the resources are written.

Summary

Public Constructors
ResponseCache()
Creates a new instance of this class.
Public Methods
abstract CacheResponse get(URI uri, String rqstMethod, Map<StringList<String>> rqstHeaders)
Gets the cached response according to the requesting URI, method and headers.
static ResponseCache getDefault()
Gets the default response cache of the system.
abstract CacheRequest put(URI uri, URLConnection conn)
Allows the protocol handler to cache data after retrieving resources.
static void setDefault(ResponseCache responseCache)
Sets the default response cache of the system.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ResponseCache ()

Creates a new instance of this class.

Public Methods

public abstract CacheResponse get (URI uri, String rqstMethod, Map<StringList<String>> rqstHeaders)

Gets the cached response according to the requesting URI, method and headers.

Parameters
uri the requesting URI.
rqstMethod the requesting method.
rqstHeaders a map of requesting 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.
IllegalArgumentException if any one of the parameters is set to null.

public static ResponseCache getDefault ()

Gets the default response cache of the system.

Returns
  • the default ResponseCache.
Throws
SecurityException if a security manager is installed but it doesn't have the NetPermission("getResponseCache").

public abstract CacheRequest put (URI uri, URLConnection conn)

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 with a WriteableByteChannel to put the resource data down. Otherwise, this method returns null.

Parameters
uri the reference to the requested resource.
conn 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.
IllegalArgumentException if any one of the parameters is set to null.

public static void setDefault (ResponseCache responseCache)

Sets the default response cache of the system. Removes the system's default ResponseCache if the parameter responseCache is set to null. This setting may be ignored by some non-standard protocols.

Parameters
responseCache the ResponseCache instance to set as default or null to remove the current default ResponseCache.
Throws
SecurityException if a security manager is installed but it doesn't have the NetPermission("setResponseCache").