Most visited

Recently visited

Added in API level 1

ResponseCache

public abstract class ResponseCache
extends Object

java.lang.Object
   ↳ java.net.ResponseCache
Known Direct Subclasses


代表URLConnection缓存的实现。 通过执行ResponseCache.setDefault(ResponseCache),可以向系统注册此类的实例,系统将调用此对象以便:

The ResponseCache implementation decides which resources should be cached, and for how long they should be cached. If a request resource cannot be retrieved from the cache, then the protocol handlers will fetch the resource from its original location. The settings for URLConnection#useCaches controls whether the protocol is allowed to use a cached response. For more information on HTTP caching, see RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1

Summary

Public constructors

ResponseCache()

Public methods

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

根据请求的URI,请求方法和请求标头检索缓存的响应。

static ResponseCache getDefault()

获取系统范围的响应缓存。

abstract CacheRequest put(URI uri, URLConnection conn)

协议处理程序在获取资源后调用此方法,并且ResponseCache必须决定是否将资源存储在其缓存中。

static void setDefault(ResponseCache responseCache)

设置(或取消设置)系统级缓存。

Inherited methods

From class java.lang.Object

Public constructors

ResponseCache

Added in API level 1
ResponseCache ()

Public methods

get

Added in API level 1
CacheResponse get (URI uri, 
                String rqstMethod, 
                Map<StringList<String>> rqstHeaders)

根据请求的URI,请求方法和请求标头检索缓存的响应。 通常,在发送请求获取网络资源之前,协议处理程序会调用此方法。 如果返回缓存的响应,则使用该资源。

Parameters
uri URI: a URI used to reference the requested network resource
rqstMethod String: a String representing the request method
rqstHeaders Map: - a Map from request header field names to lists of field values representing the current request headers
Returns
CacheResponse a CacheResponse instance if available from cache, or null otherwise
Throws
IOException if an I/O error occurs
IllegalArgumentException if any one of the arguments is null

也可以看看:

getDefault

Added in API level 1
ResponseCache getDefault ()

获取系统范围的响应缓存。

Returns
ResponseCache the system-wide ResponseCache
Throws
SecurityException If a security manager has been installed and it denies NetPermission("getResponseCache")

也可以看看:

put

Added in API level 1
CacheRequest put (URI uri, 
                URLConnection conn)

协议处理程序在获取资源后调用此方法,并且ResponseCache必须决定是否将资源存储在其缓存中。 如果要缓存资源,put()必须返回一个CacheRequest对象,该对象包含协议处理程序将用于将资源写入缓存的OutputStream。 如果资源不被缓存,则put必须返回null。

Parameters
uri URI: a URI used to reference the requested network resource
conn URLConnection: - a URLConnection instance that is used to fetch the response to be cached
Returns
CacheRequest a CacheRequest for recording the response to be cached. Null return indicates that the caller does not intend to cache the response.
Throws
IOException if an I/O error occurs
IllegalArgumentException if any one of the arguments is null

setDefault

Added in API level 1
void setDefault (ResponseCache responseCache)

设置(或取消设置)系统级缓存。 注意:非标准的procotol处理程序可能会忽略此设置。

Parameters
responseCache ResponseCache: The response cache, or null to unset the cache.
Throws
SecurityException If a security manager has been installed and it denies NetPermission("setResponseCache")

也可以看看:

Hooray!