VOOZH about

URL: https://www.geeksforgeeks.org/java/java-net-responsecache-class-in-java/

⇱ java.net.ResponseCache Class in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

java.net.ResponseCache Class in Java

Last Updated : 29 Mar, 2021

ResponseCache in java is used for constructing implementation of URLConnection caches, and it nominates which resource has to be cached and up to what time duration a resource needed to be cached.

An instance of ResponseCache can be created using the system by doing :

ResponseCache.setDefault(ResponseCache)

The instance created by using the above statement will call an object of ResponseCache in order to :

  1. For storing resource data that has been which has been retrieved from an external source into the cache.
  2. For fetching a resource that has been stored in the cache on request.
  3. Response cache can be imported through java.net package

java.net.ResponseCache

Methods of ResponseCache class :

MethodDescription
get(URI uri, String rqstMethod, Map<String,List<String> > rqstHeaders)This method is used for retrieving the cached response depending upon the requesting URI, request method and request headers.
getDefault()This method is used for retrieving the system-wide cache response.
put(URI uri, URLConnection conn)The protocol handler calls this method whenever a resource has been retrieved and the ResponseCache must decide whether to store the resource in its cache.
setDefault(ResponseCache responseCache)This method is used to set or unset the system-wide cache

Applications of ResponseCache class :   

1. In the java.net package, ResponseCache is used for implementing for caching of resources for various network applications such as :

  1. Email
  2. File Transfer
  3. Remote Terminal Access
  4. Loading web pages

java.net.ResponseCache

2. In java.net, ResponseCache is applied in fetching out system-wide response cache.

public static ResponseCache.getDefault()

3. In java.net, ResponseCcahe is used in setting or unsetting out the system-wide cache.

public static void ResponseCache.setDefault(ResponseCache responseCache)

Java program for implementing java.net.ResponseCache :

Output :

👁 Image
Comment
Article Tags: