Hi,

Due to bug https://issues.apache.org/jira/browse/CB-3071, the cached response 
gets invalidated after each time restarting the iOS cordova app, the suggested 
workaround is to use the open source SDURLCache project, however, SDURLCache is 
not a good candidate to replace the iOS default NSURLCache, as it does not 
follow the RFC 2616 specification very well, and cannot be used in many 
projects that requires serious cache functions.

The testing shows the issue of CB-3071 is related to the iOS cordova useragaent 
logic. When each time the app restarts, the uiWebView will get a new address, 
and this address is appended to the UIWebView's user agent string, so the user 
agent is different for each running session.  iOS will automatically invalidate 
the cached response if it detects the user agent has been changed, as user 
agent contains locale information, and if locale setting is changed, the same 
url may get the different response from server side.

This can be verified by always appending a constant number  to the user agent 
string, in that case,  the cached response can be loaded after the app restarts

It seems the issue can be fixed by changing the current NSMutableSet* 
gRegisteredControllers to NSMutalbleDictionary object, the dictionary object 
uses a incremental sequential id as key, and use the view controller’s address 
as value, then only appending the sequential id in the user agent string. This 
sequential id can be used to find the corresponding view controller from 
gRegisteredControllers collection. As most cordova app will only create a 
single CDVViewController, so the sequential id most likely is always 0. This 
will generate the same user agent string across app running sessions,  and keep 
the cached response valid.

Please let me know if the bug CB-3071 can be reopened and get fixed with this 
idea.

Thanks
Jonathan

Reply via email to