IOS URL caching when not needed (IMHO)

Does anyone know why this request is being cached?

  • I am using unmodified .default

    URLSessionConfiguration

    .

  • Response headers:

(from Charles, confirmed from debug answer in data task 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 check that the request is cached using the Charles proxy - the first request appears, but there are no subsequent requests.

  • Using session configuration .ephemeral

    or setting a custom url cache from 0 for memory and disk size, display all requests in Charles, so I know Charles is a valid test.

I always assumed that without the cache headers, the response would not be cached: |

Anyone ideas?


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

      

+3


source to share


1 answer


I always assumed that without the cache headers, the response would not be cached: |

Not how it works, it will cache responses even without headers Cache-Control

or Expires

if all other criteria are met . However, it will use heuristics to determine the cached response freshness, since the exact expiration time was not specified in the response headers. NSURLCache

is implemented in accordance with section 13 of RFC 2616 , and this behavior is specified there.



For more information, you can check the following articles:

+4


source







All Articles