我正在使用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
super.clearCache();
- Alex