iOS 不应该缓存的 URLCache(恕我直言)

iOS URLCache caching when it shouldn't (IMHO)

有谁知道为什么要缓存此请求?

(来自 Charles,通过调试数据任务完成块中的响应确认)

{
    "Accept-Ranges" = bytes;
    "Content-Length" = 1480;
    "Content-Type" = "application/json";
    Date = "Mon, 22 May 2017 19:14:13 GMT";
    Etag = "\"42bebc5fb88323b8cd145ed85ea7a018\"";
    "Last-Modified" = "Mon, 22 May 2017 14:54:38 GMT";
    Server = AmazonS3;
    "x-amz-id-2" = "abcdefghijklmn";
    "x-amz-request-id" = 1A2B3C4D5E;
}

我一直假设没有缓存 headers 响应不会被缓存 :|

有什么想法吗?


编辑:这是我提出的请求

po task.originalRequest
▿ Optional<URLRequest>
  ▿ some : http://s3-eu-west-1.amazonaws.com/path/path/configuration.json
    ▿ url : Optional<URL>
      ▿ some : http://s3-eu-west-1.amazonaws.com/path/path/configuration.json
    - cachePolicy : 0
    - timeoutInterval : 60.0
    - mainDocumentURL : nil
    - networkServiceType : __ObjC.NSURLRequest.NetworkServiceType
    - allowsCellularAccess : true
    ▿ httpMethod : Optional<String>
      - some : "GET"
    - allHTTPHeaderFields : nil
    - httpBody : nil
    - httpBodyStream : nil
    - httpShouldHandleCookies : true
    - httpShouldUsePipelining : false

I've always assumed that without cache headers a response won't be cached :|

这不是它的工作原理,即使没有 Cache-ControlExpires headers,它也会缓存响应,如果 all other criteria met. However, it will use heuristics for determining cached response freshness, as exact expiration time was not provided in response headers. NSURLCache is implemented according to section 13 of RFC 2616 并且此行为在此处说明。

有关更多信息,您可以查看以下文章: