-1

In my application I am using Webview and loading a data which I am getting from the webserver. In this it's working fine but issue is I used NSURLRequest object for sending request to the server. And I wrote the code as such below

NSMutableURLRequest * webPageRequest=[NSMutableURLRequest requestWithURL:webPageUrl cachePolicy:2 timeoutInterval:60.0];

Here the data is caching in memory successfully. But issue is when ever I open app it is always giving old data. It's not sending a request to the server for new data and even the app data is also not updating. I am supporting both IOS6 & IOS7.

So can you please let me know how to resolve this issue. And may I know how long the data will be available in Cache memory. And how NSURLRequestReturnCacheDataElseLoad will work means at what situation this method will execute.

halfer
  • 19,824
  • 17
  • 99
  • 186
user3341324
  • 45
  • 1
  • 9

1 Answers1

4

The issue you can see the old data is because the NSURLRequestReturnCacheDataElseLoad, see this (it has been taken from NSHister:

NSURLRequestReturnCacheDataElseLoad: Existing cached data should be used, regardless of its age or expiration date. If there is no existing data in the cache corresponding to the request, the data is loaded from the originating source.

Check out this link you should find the way to use right policy for your purpose.

Greg
  • 25,317
  • 6
  • 53
  • 62
  • HI greg thanks for your great support. So Based on the explanation in link. I am getting old data from the cache always. May i know is there any timeout in getting old data. So based on my requirement is this NSURLRequestReloadRevalidatingCacheData: policy is suitable for me right ? – user3341324 Mar 07 '14 at 15:10
  • You have to read about all of the policy and pick one which suit you best. Do some research on cache expiration in that way you can set up lets say 1h expiration and your cache will be kept just for one hour. – Greg Mar 07 '14 at 15:18
  • For POST will it load from cache? its happening for me – Mohammad Sadiq Shaikh Feb 10 '16 at 13:17