0

In my project I'm working with NSMutableURLRequest. Sometimes there are mistakes because of caching.

So I did

    let mutableURLRequest = makeURLRequestFrom(url: url, httpMethod: "GET", httpHeaders: httpHeaders, parameters: parameters)
    mutableURLRequest.cachePolicy = .ReloadIgnoringLocalAndRemoteCacheData

This is working fine. Now I don't want to set the cachePolicy for every NSMutableURLRequest. Is there a possibility to set a standard config for the cachePolicy?

For UI-elements I can set configs in the Appdelegate for the whole project, too.

Like this:

UILabel.appearance().textColor =  UIColor.red()

Maybe there is a similar solution for the cachePolicy? (I can't find yet)

kuzdu
  • 5,943
  • 1
  • 37
  • 56

1 Answers1

0

If you're using NSURLSession, you can specify a per-session cache policy. For NSURLConnection, I think the best you could do would be to modify the shared NSURLCache object and set its in-memory and on-disk sizes to zero, though I can't guarantee that the OS will honor that.

dgatwood
  • 9,519
  • 1
  • 24
  • 48
  • wow thanks for this answer. But I decided to set the cache policy manually for every the mutableRequest. It's dirty, but it works – kuzdu May 03 '16 at 08:45