App42 iOS SDK now supports offline caching and storage that will make your iOS application responsive even if the network is not available and user can use your application flawlessly without any trouble. Offline caching enables your application to read data from local cache if network is not available.Using this feature is quite straight forward and requires a single line of code to enable it.
Offline Caching and Storage can be used in isolation or they can be used along with each other based on your app requirement. You can enable these features as explained below.
Caching allows applications to read data from its local cache depending on the policy that you have set.
App42 allows 3 different cache policies that we have discussed below.
- APP42_CACHE_FIRST: This policy enables apps to first look for the cached response for all the READ requests and returns the valid cached data if available otherwise the request will be sent to the server. Valid cached response means, if the cached response is not expired.
- APP42_NETWORK_FIRST: This policy will try to send request to the server if the network is available otherwise it will look for the cached response.
- APP42_NO_CACHE: This is a default policy and follows the normal flow i.e. it sends every request directly to the server.
Note: The expiry time for cached response is set by default to 24 hours but you can always overwrite using our API as explained below:
[[App42CacheManager sharedCacheManager] setPolicy:APP42_CACHE_FIRST]; //Setting the Policy [[App42CacheManager sharedCacheManager] setExpiryInMinutes:
]; // Setting expiry time
Before talking of the details, let us go through some use cases.
- User is playing your game and the data like score needs to be saved to the cloud but there is no network.
- User wants to post his status in a social app and there is no network.
- User wants to modify his existing note but there is no network available.
There may be such use cases and as a result, the application may lose the activity of that particular user, which may be disappointment and this is where this feature will help.
Offline Storage allows application to save requests (POST, PUT and DELETE) locally in the application cache when it runs offline and sends them to server when it goes online.
Enabling this feature is a single step process which is as follows.
[App42API setOfflineStorage:YES]; //Enabling Offline Storage