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

1

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Do you have any official document saying NSURLCache doesn't support?
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."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.