我正在使用HttpUrlConnection来获取服务器请求而HttpResponseCache 用于缓存响应。但是没有为PUT请求缓存响应,有人知道是什么原因吗?缓存是否仅适用于POST和GET方法?
答案 0 :(得分:0)
某些HTTP方法必须导致缓存使实体无效。这可以是Request-URI引用的实体,也可以是Location或Content-Location头(如果存在)。这些方法是:
- PUT
- DELETE
- POST
答案 1 :(得分:0)
来自HttpResponseCache的源代码的注释表明未实现非GET的缓存:
/*
* 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;