【问题标题】:HttpResponseCache 'PUT' request method are not getting cachedHttpResponseCache 'PUT' 请求方法没有被缓存
【发布时间】:2014-04-01 07:20:57
【问题描述】:

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

【问题讨论】:

    标签: java android httpurlconnection


    【解决方案1】:

    来自 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;
    

    【讨论】:

      【解决方案2】:

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

      • 删除
      • 发布

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

      【讨论】:

        猜你喜欢
        • 2018-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-13
        • 1970-01-01
        • 2017-04-29
        • 2014-11-25
        • 2012-07-30
        相关资源
        最近更新 更多