3

I'm developing a app with PhoneGap/Cordova 2.5.0 and I'm making AJAX calls with jQuery 1.8.2 to retrieve datas from an external server. I'm doing a lot of requests and I can see my app cache growing up, and this is not pretty cool...

I've tested many things like :

$.ajaxSetup({ 
    cache: false,
    headers: { 
        "Cache-Control": "no-cache"
    }
});

OR / AND

var ajaxRequests = {}; // Limit one AJAX call for each "data_id" to prevent numbers calls
if (vrbd.ajaxRequests[data_id] === undefined) {
    ajaxRequests[data_id] = $.ajax({
        type:       'GET',
        dataType:   'xml' + data_id,
        url:        url,
        data:       {
            _: new Date().getTime() + Math.random()
        },
        async:      true,
        timeout:    (data_count >= 2 ? data_count * 800 : 2000),
        cache:      false,
        headers: { 
            "Cache-Control": "no-cache"
        }
    })
    .done(function(data, textStatus, jqXHR) { ... })
    .fail(function(jqXHR, textStatus, errorThrown) { ... })
    .always(function(jqXHR, textStatus) { delete ajaxRequests[data_id]; });
}

If I let my app running during a couple of hours, I can see my cache growing up from about 160kb to about 30Mb in Settings > Apps > MyApp > Cache (AVD and real device).

So, didn't I understand anything about the cache in Settings or did I forget something ?

Please, let me know if you need another informations, sorry for my english, and thanks in advance for your help.

Best regards Alex

Alex
  • 537
  • 5
  • 17
  • 2
    _I want to edit to add "Hi all," but it seems it takes no effects... So, Hi all ;-)_ – Alex Mar 04 '13 at 11:08
  • I found a workaround from this link, but I'm still waiting to know if there is a better way to not feeding Android cache (clear cache on destroy or no feed cache at all). [Programmatically clear PhoneGap/Cordova app's cache on Android to simulate a fresh install?](http://stackoverflow.com/questions/11159280/programmatically-clear-phonegap-cordova-apps-cache-on-android-to-simulate-a-fre) `super.clearCache();` – Alex Mar 04 '13 at 15:09

1 Answers1

0

Clear cache:

// clear cache
super.clearCache();
super.loadUrl("file:///android_asset/www/index.html");

Source: Adding a splash screen and clearing cache with PhoneGap and Android

Richard Muthwill
  • 320
  • 2
  • 16