My app's webView loads a page and I inject some javascript which automates a click for me and adds an item to my wish list. For something like this would you recommend using a data session or an ephemeral session to load the page? Speed is important to me, and I'm trying to optimize is as much as I can in Objective-C (yupp, even milliseconds).
The page basically loads a product page so everything but the actual product is always going to be the same (background view, website menu bar, button images, etc). Right now I'm using NSURLConnection, and I'm trying to update my code to use NSURLSession instead.
Default sessions behave similarly to other Foundation methods for downloading URLs. They use a persistent disk-based cache and store credentials in the user’s keychain.
Configuration that uses global or shared cookie, cache and credential storage objects. Behaviour is similar to NSURLConnection.
The shared session uses the global singleton credential, cache and cookie storage objects. This can be used in place of existing code that uses +[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
Ephemeral sessions do not store any data to disk; all caches, credential stores, and so on are kept in RAM and tied to the session. Thus, when your app invalidates the session, they are purged automatically.
Background sessions are similar to default sessions, except that a separate process handles all data transfers. Background sessions have some additional limitations, described in “Background Transfer Considerations.”
Background session is similar to Default session, But it can be used to perform networking operations on behalf of a suspended application, within certain constraints.
Similar to default session but upload or download of data can be performed even when the application is in suspended state.
Reference from Apple Doc
//Default session
+ (NSURLSessionConfiguration *)defaultSessionConfiguration;
//Ephemeral
+ (NSURLSessionConfiguration *)ephemeralSessionConfiguration;
//Background
+ (NSURLSessionConfiguration *)backgroundSessionConfiguration:(NSString *)identifier;
NSURLSession Tasks and Delegates
Below image explains types of NSURLSession Tasks and their hierarchy.
More Details
I think you'd use a default session as you want it to cache data to disk. Something an ephemeral session doesn't
The bottleneck is almost always IO so you want caching when the data doesn't change anyways. For rapidly chaining data this wouldn't be worth it but you explicitly say that the data won't change
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With