1

I am setting cachePolicy on url request. First call to an url (GET) return status code in 200. Second call to the same url return 200.

If use a rest client i obtain for the first call 200, and for the second, with properly header ( If-None-Match) 304

Reading online i understand that iOS serialize first request with status code 200 and retrieve it for the second call.

There is a way to obtain 304 instead of 200 in UrlCache or understand if it the data came from cache and not from network.

Andrea Bozza
  • 1,038
  • 2
  • 9
  • 30
  • https://stackoverflow.com/questions/40976132/how-to-know-if-nsurlsessiondatatask-response-came-from-cache – Leo Dabus Nov 17 '17 at 17:03

1 Answers1

2

From http://jonathanblog2000.blogspot.com/2017/07/ios-uiwebview-nsurlsession-cache.html :

If you want to test and verify the cache works properly in your app, you have to log the device http traffic, as the delegate of NSURLSession will never see the 304 status code returned from server, it will be automatically replaced by the status code in the cached response.

This is a good thing. This means your app can just pretend you got a successful response, and not worry about how the response was obtained or what sort of optimizations was happening. You just deal with the response the same way regardless of whether it was pulled from the cache or not.

dotMorten
  • 1,803
  • 1
  • 12
  • 9