Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Data Sessions vs Ephemeral Sessions

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.

like image 457
KingPolygon Avatar asked Jan 05 '14 21:01

KingPolygon


2 Answers

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.

  1. Configuration that uses global or shared cookie, cache and credential storage objects. Behaviour is similar to NSURLConnection.

  2. 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.

  1. Private Session Configuration that does not persist cookie, cache and credential storage objects. As the name indicates, the configuration settings are short living and are deleted when the session is invalidated.

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.”

  1. 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.

  2. 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

enter image description here

like image 196
codercat Avatar answered Oct 23 '22 06:10

codercat


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

like image 24
Daij-Djan Avatar answered Oct 23 '22 06:10

Daij-Djan