MugunthKumar/MKNetworkKit — Issue #6: How to support "cache only" behavior?
Author: viggiosoft
Created: 2011-12-08 16:15:54+00:00
State: open

I prefer to explain my problem before: on an app that I'm working on I agreed with the web service developer the following two simple rules:

1. all "dynamic" requests will be run, and if the app is offline the cached data will be reused: this approach is perfectly done using MKNetworkKit cache management

2. all "static resources" should be downloaded from the network only if not cached yet; if they're cached they must be used and no re-download from the network is needed; this approach is safe because the agreement with the web service developer is such that if a specific resource must be changed (e.g. the photo of a particular item) its URL will change and in this case we would have a "cache fault" which will require network download.

Unfortunately this 2nd approach is not feasible with MKNetworkKit, as the cached data will be reused but later a new network access will be run again. This requires a lot of unneeded network operations while most of the resources need to be downloaded once only.

My first idea would be to replace the "forceReload" argument with a "cache policy" one with the following states:
1. don't use cache
2. use cache and then reload
3. reload only if no cache
But probably it is better to move this as a network engine parameter (global setting) and operation parameter (local setting), something similar is already done by ASIHTTPRequest.

Or is there a better way to work with this?

Thank you

Carlo