iosmultithreadingcachingnsurlcacheurlsession

Is NSURLCache thread safe?


I know NSCache is thread safe, however I can't find out any document mentioned that NSURLCache is thread safe.


Solution

  • Normally I'd take @bbum's stance on this, but in the case of NSURLCache disagree.

    NSURLConnection is thread safe, in the sense that a given instance can be scheduled on a thread of your choosing (but don't try to schedule a single instance on multiple threads!)

    By default, connections all interact with +[NSURLCache sharedCache]. Logically, this means either NSURLCache is itself thread safe, or offers a locking mechanism which clients can explicitly call themselves. Since the latter doesn't exist, I deduce NSURLCache is thread safe.

    Would still like this to be documented officially, mind!