deanWombourne
deanWombourne

Reputation: 38485

iOS URLCache caching when it shouldn't (IMHO)

Does anyone know why this request is being cached?

(from Charles, confirmed from debugging the response in the data tasks's completion block)

{
    "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;
}

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

Any ideas anyone?


EDIT: Here's the request I'm making

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

Upvotes: 5

Views: 833

Answers (1)

Maxim Pavlov
Maxim Pavlov

Reputation: 2972

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

That's not how it works, it WILL cache responses even without Cache-Control or Expires headers, if 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 and this behavior is stated there.

For more information you can check the following articles:

Upvotes: 8

Related Questions