Is NSData + (id)dataWithContentsOfURL:(NSURL *)aURL options:(NSDataReadingOptions)mask error:(NSError **)errorPtr: cached automatically?

ios, nsdata, nsurlconnection

Solution

There is no answer to your specific question which refer to the caches managed by the URL loading system.

The reading options in method `dataWithContentsOfFile:options:error:` refer solely to reading from the file system (please consult to the official documentation of `NSDataReadingOptions`).

Unfortunately, the documentation gives no hint about the behavior when reading from remote resources. Whether the response is cached in the URL cache is unspecified - that is, we don't know, and the internal behavior and implementation can change with each new OS version.

IMHO, we should generally avoid to use the "convenient methods" to read from remote resources. It appears, these methods work only by "accident" when accessing remote resources. So, I strongly agree with @Wayne Hartman ;)

Problem

When I read the section on ``` NSDataReadingOptions Options for methods used to read NSData objects. enum { NSDataReadingMappedIfSafe = 1UL << 0, NSDataReadingUncached = 1UL << 1, NSDataReadingMappedAlways = 1UL << 3, }; typedef NSUInteger NSDataReadingOptions; ``` It says that NSDataReadingUncached A hint indicating the file should not be stored in the file-system caches. For data being read once and discarded, this option can improve performance. Available in OS X v10.6 and later. Declared in NSData.h. So I am assuming that by default these URL requests are cached and there is no need to implement NSURLRequest to cache data if I want to use shared global cache ? Is this understanding correct ?

Original source

Related problems