ResponseCache
public abstract class ResponseCache
extends Object
Known Direct Subclasses
|
代表URLConnection缓存的实现。 通过执行ResponseCache.setDefault(ResponseCache),可以向系统注册此类的实例,系统将调用此对象以便:
- store resource data which has been retrieved from an external source into the cache
- try to fetch a requested resource that may have been stored in the cache
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
ResponseCache ()
Public methods
get
CacheResponse get (URI uri,
String rqstMethod,
Map<String, List<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 |
put
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. |
setDefault
void setDefault (ResponseCache responseCache)
设置(或取消设置)系统级缓存。 注意:非标准的procotol处理程序可能会忽略此设置。
Parameters |
responseCache |
ResponseCache : The response cache, or null to unset the cache. |