0

I have setup an NSURLCache and set the sharedcache to the initialized cache.

I can see the cache size growing when I log the size in the NSURLConnection delegates.

For some reason when requesting the same data, a request is made to the server again, and the log of the cache size shows the log staying the same size.

This indicates to me that the cache is working correctly, but for some reason the URL Loader is not pulling from the cache.

I use the default cache policy on the requests and have double checked the headers in the response.

After reading around on here I see other people mentioning the same issue and setting the memory capacity and disk capacity to the same value solves their issue, but it does not work for me. New requests are being made every time rather than pulling from the cache.

Would it be wise to instead check the cache for the data before making the request? I dont see the point of the cachingPolicy parameter to the NSURLRequest method.

some_id
  • 29,466
  • 62
  • 182
  • 304
  • By chance does your URL have a query string? – AlBeebe Nov 14 '12 at 13:23
  • @AlBeebe Thanks, yes it does have a query string. How would it effect the cache? – some_id Nov 14 '12 at 13:51
  • it wont cache automaticallly – Daij-Djan Nov 14 '12 at 13:54
  • I see the cache size growing. How does one see what is in the cache itself? So I should override the caching delegate method for writing and check for the object in cache for reading instead of relying on the caching policy? – some_id Nov 14 '12 at 14:36
  • I don't think it will cache if you use a query string. Do a quick test to see if it caches the response when you don't pass a query string. Maybe its possible your query string keeps changing each time you make a request for instance if one of the parameters is say the time. – AlBeebe Nov 14 '12 at 15:48
  • The query string is the same. The request is exactly the same. – some_id Nov 14 '12 at 17:33
  • This is an old question, but to answer "how does one see what is in the cache itself", a cache is no more than a sqlite database located (in development) in 'iOSSDKVersion'->Applications->yourAppIdentifier->Caches->bundleIdentifier->Cache.db if you open this file with a sqllite client you can see everything, from the request to the object itself. – Leonardo Feb 11 '13 at 20:48

1 Answers1

0

well HTTP also lets the server tell you how to cache - it can disallow caching (and also set a max. cache time)

that may influence SDURLCache


anyways, also look at UIWebView and NSURLCache have a troubled relationship

there it is said that UIWebView doesnt work

Community
  • 1
  • 1
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Yes, I saw that thanks, but I am not using a UIWebView. Im not sure how SDURLCache is relevant. The http header contains all the needed caching information. – some_id Nov 14 '12 at 13:48
  • SDURLCache - nsurlcache . sorry misread. but my first point stands.. but if the response headers look good, its weird – Daij-Djan Nov 14 '12 at 13:50