I'm creating an NSURLSession
with a sessionConfiguration where I have explicitly set the requestCachePolicy
and URLCache
.
sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfiguration.requestCachePolicy = NSURLRequestReturnCacheDataElseLoad;
sessionConfiguration.URLCache = [NSURLCache sharedURLCache];
A request is created and passed as an argument in NSURLSession
dataTaskWithRequest:CompletionHandler:
method. The request is constructed like this:
request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:kAENServiceNetworkTimeout];
Problem 1:
Setting up like this, no fsCachedData
Folder is created on disk and cached data is not used. If the request is created simply using:
request = [NSMutableURLRequest requestWithURL:url];
The cache is created on disk, and the image is used as expected. Is this a bug in Apple's code?
Problem 2:
In neither of these cases is the URLSession:dataTask:willCacheResponse:completionHandler:
delegate method called. Are their situations under which this would be the case?
Update:
I've pushed an example project to Github, https://github.com/mattmorton/cache-testing