0

I'm curious about NSURLCache, NSURLRequest has some policy of cache, like NSURLRequestUseProtocolCachePolicy, NSURLRequestReturnCacheDataElseLoad, but after read them, either of them are using local cache data, or not using cache, My question is if I want start a url request, first I wanna load cache and render ui, then continue interacting with server to grab latest data and refresh the ui, which policy is my choice?

Vincent Guerci
  • 14,379
  • 4
  • 50
  • 56
NickYu
  • 594
  • 1
  • 5
  • 13

1 Answers1

0

If I understand correctly what you want to achieve (get data quickly from the cache to show in the UI even if it is outdated, then get the current data even if it is slow), you'd have to make two requests, using different cache policies. I'd start the second request only when the first one has finished, and examine the result of the first request first, because the data might not have been available in the cache, so the first request might already returned the uncached data that you wanted.

gnasher729
  • 51,477
  • 5
  • 75
  • 98