My app makes a lots of server requests, and its results constantly changes. I want to know if it is possible, when I enter in a view controller, to load data from cache (so, it doesn't appear empty), and then loads from server to update the view with the new data. I checked the different cache policies but none of them does that. Can anyone tell me the proper way to do this?
Asked
Active
Viewed 58 times
2 Answers
1
You can implement this in 2 steps:
in the viewWillAppear you can asynchronously request the data setting the cache policy to NSURLRequestReturnCacheDataDontLoad. When the response is available you should update your UI with the data.
after this, on viewDidAppear for example, you can start an asynchronous request that has the cache policy set to NSURLRequestReloadIgnoringLocalCacheData.

Gabi D
- 199
- 1
- 8
-
This seems a good solution. Unfortunately, I'm having problems changing the cache policy for a single request. I checked this solution http://stackoverflow.com/questions/29052322/afnetworking-2-0-afhttprequestoperationmanager-cachepolicy-not-working but doesn't work either – Oscar J. Irun Oct 26 '15 at 16:33
-
I'm sorry for this. Their documentation says it should work. – Gabi D Oct 26 '15 at 17:04
0
I think the best way is to use CoreData for save the previous requests. Load some data from the local data base and after the request completes update the view controller.
Cheers.

user3820674
- 262
- 1
- 6