ResponseCache.setDefault(ResponseCache): This method is available in java.net.ResponseCache class of Java.
Syntax:
void java.net.ResponseCache.setDefault(ResponseCache responseCache)
This method takes one argument. This method sets (or unsets) the system-wide cache.
Note: non-standard protocol handlers may ignore this setting.
Parameters: One parameter is required for this method.
responseCache: The response cache, or null to unset the cache.
Throws:
1. SecurityException - If a security manager has been installed and it denies NetPermission("setResponseCache").
Approach
Java
package com.ResponseCache;import java.io.IOException;import java.net.CacheRequest;import java.net.CacheResponse;import java.net.ResponseCache;import java.net.URI;import java.net.URLConnection;import java.util.List;import java.util.Map;public class ResponseCachesetDefault {public static void main(String[] args) {ResponseCache responseCache = new ResponseCache() {@Overridepublic CacheResponse get(URI uri, String rqstMethod, Map<String, List<String>> rqstHeaders)throws IOException {return null;}@Overridepublic CacheRequest put(URI uri, URLConnection conn) throws IOException {return null;}};ResponseCache.setDefault(responseCache);System.out.println("Successfully sets default responsecache");}}
Output:
Successfully sets default responsecache
Some other methods of ResponseCache class
get(URI, String, Map): This method retrieves the cached response based on the requested URI, the request method, and the request headers. Typically this method is called by the protocol handler before it sends out the request to get the network resource. If a cached response is returned, that resource is used instead.
ResponseCache.getDefault(): This method gets the system-wide response cache.
put(URI, URLConnection): The protocol handler calls this method after a resource has been retrieved, and the ResponseCache must decide whether or not to store the resource in its cache.
ResponseCache.setDefault(ResponseCache): This method sets (or unsets) the system-wide cache.
No comments:
Post a Comment