Does anyone know why this request is being cached?
I'm using an unmodified .default
URLSessionConfiguration
.
The response headers are:
(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'm verifying that the request is cached using Charles proxy - the first request appears, but subsequent requests don't.
Using .ephemeral
session configuration, or setting a custom url cache with 0 for memory and disk size shows all the requests in Charles, so I know Charles is a valid test.
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
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With