HttpResponseCache'PUT'请求方法没有被缓存

时间:2014-02-28 10:35:37

标签: java android httpurlconnection

我正在使用HttpUrlConnection来获取服务器请求而HttpResponseCache 用于缓存响应。但是没有为PUT请求缓存响应,有人知道是什么原因吗?缓存是否仅适用于POST和GET方法?

2 个答案:

答案 0 :(得分:0)

  

某些HTTP方法必须导致缓存使实体无效。这可以是Request-URI引用的实体,也可以是Location或Content-Location头(如果存在)。这些方法是:

     
      
  • PUT
  •   
  • DELETE
  •   
  • POST
  •   

http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

答案 1 :(得分:0)

来自HttpResponseCache的源代码的注释表明未实现非GET的缓存:

https://android.googlesource.com/platform/libcore/+/cff1616012dc0d56c2da9af2b9b1183e76c7e044/luni/src/main/java/libcore/net/http/HttpResponseCache.java

    /*
     * Don't cache non-GET responses. We're technically allowed to cache
     * HEAD requests and some POST requests, but the complexity of doing
     * so is high and the benefit is low.
     */
   return null;