3

I am downloading WMS tiles which I want to cache. I'm using AFNetworking which includes NSURLCache. The responses from the server do not contain Cache-Control protocols in the header.

I asked the server guy about this and was unfamiliar with server side cache-control. At the moment, he is swamped with other work. Do I need him to implement the cache-control or can I force NSURLCache to cache them w/out the info the response header?

Is NSURLCache persistent? If so, how can I clear the cache? The tiles will need to be retrieved per session and can not be persistent.

Or should I create my own cache?

Padin215
  • 7,444
  • 13
  • 65
  • 103

1 Answers1

0

When you activate NSURLCache it will work for any request that is based on the NSUrlRequest (like AFNetworking). The moment you activate the NSURLCache you can specify it's maximum size. You can also clear the cache by calling the removeAllCachedResponses or removeCachedResponsesForRequest methods. If the server does not send any cache control information, then the cache will still cache the file. If you want complete control over the cache, you could create your own cache. If you would like to see a sample code for that, then have a look at https://github.com/evermeer/EVURLCache

Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
  • Ok, good to hear. talked to the server guy again and he didn't seem too excited to implement cache-controls. So, this may seem really basic, but how does retrieving from NSURLCache work? Is it just handled in the backend? I make the request and the NSURLRequest checks locally if and so, returns it w/out me doing anything extra? – Padin215 Apr 16 '13 at 14:00
  • 1
    on app startup you just initialize the cache. From that moment all NSURLrequests will be handled by the NSURLCache. When you create a NSURLrequest you can specify the caching policy like NSURLCacheStorageAllowed. – Edwin Vermeer Apr 16 '13 at 14:10