[WikimediaMobile] Caching in Android / PhoneGap app

Brion Vibber bvibber at wikimedia.org
Fri Dec 9 22:40:02 UTC 2011


I'm having some positive results in preliminary tests simply switching the
cache mode on the WebView.

Getting rid of the urlcache bits which we've had problems with, and adding
this into WikipediaActivity.java.onCreate():


this.appView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

lets me go back to previously-visited pages without complaint after
switching on airplane mode -- and very quickly!


However, any loading that *fails* (such as a page that hasn't been cached)
triggers an application-fatal error, as far as I can tell because DroidGap
assumes that iframes don't exist and the only thing that might fail to load
is the entire application. :P This may just have to be hacked around by
modifying the phonegap infrastructure. :P


Some potential issues with this approach:
* not sure if/how to control the amount of space used for caching
* (though you should be able to clear it manually from the standard Manage
Applications panel on the phone)
* presumably we should load from network first if we're online, so would
need to swap this mode dynamically or else find a better behavior
* not sure if any way to tell what's in cache ahead of time
* of course since it's platform-dependent, similar behavior would need to
be tweaked on other platforms



A couple other possibilities include:

1) Making an "HTTP caching proxy"-like layer that we slide under the
ability to override how requests are made.

Again, this would be platform-specific and may need to be reimplemented in
the backend for other platforms. Advantage: makes our JS-side code super
easy as it would just try to load things and they'd show up. We can control
the return results, so errors wouldn't have to trigger the fatal code as
above.


2) Do platform-independent 'caching' by slurping the contents of pages
within JavaScript after loading, and managing the re-loading from cache
ourselves when offline

* Still needs the android fix for not dying when a connection fails. :P
* may not be able to handle images this way
* could explode with JS stuff :)

-- brion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wikimedia.org/pipermail/mobile-l/attachments/20111209/fe1092a0/attachment.htm 


More information about the Mobile-l mailing list