3


I'm getting data from backend using AFNetworking and set request's cachePolicy as NSURLRequestUseProtocolCachePolicy.
The response headers contain ETag value and Transfer-Encoding is chunked.
Chunked Response

In the second time I call the same API, it gets the fresh data instead of getting from cache as expected.

I notice that if the response is not chunked (contain Content-Length header), caching work perfectly
not chunked response

My question is: is it possible to cache chunked response in iOS?
Thank you for any advice

Hai Hw
  • 1,397
  • 1
  • 16
  • 24

1 Answers1

0

NSURLCache, which AFNetworking uses for caching, doesn't support caching this type of request.

You could try:

  • using SDURLCache, an open-source alternative that gives you more control, or
  • subclassing NSURLCache yourself to roll your own implementation
  • using requests that have supported caching headers
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • Do you have any official document saying NSURLCache doesn't support? – Hai Hw Apr 10 '15 at 17:32
  • from the NSURLRequest documentation: "If you are making HTTP or HTTPS byte-range requests, always use the NSURLRequestReloadIgnoringLocalCacheData policy. To learn more, read Caching Byte-Range Requests." – quellish Apr 11 '15 at 07:43