PhoneGap Android 缓存应用程序

3

我正在使用PhoneGap/Cordova 2.5.0开发一个应用程序,并使用jQuery 1.8.2进行AJAX调用,以从外部服务器检索数据。我正在进行大量请求,我可以看到我的应用程序缓存正在增长,这不太好...

我尝试了很多方法,比如:

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

或者 / 并且

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]; });
}

如果我让我的应用程序运行几个小时,我可以看到我的缓存从大约160kb增长到大约30Mb,在“设置”>“应用程序”>“MyApp”>“缓存”(AVD和真实设备)。
那么,是我没有理解设置中的缓存,还是我忘记了什么?
如有需要,请告诉我其他信息。对我的英语表示抱歉,并提前感谢您的帮助。
最好的问候, Alex

2
我想添加 "大家好," 但似乎没有起作用... 所以,大家好 ;-)_ - Alex
我从这个链接中找到了一个解决方法,但我仍在等待是否有更好的方法来避免向Android缓存提供数据(在销毁时清除缓存或根本不提供缓存)。 程序上如何在Android上清除PhoneGap/Cordova应用程序的缓存以模拟全新安装? super.clearCache(); - Alex
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接