【问题标题】:PhoneGap Android cache appPhoneGap Android 缓存应用
【发布时间】:2013-02-18 10:50:12
【问题描述】:

我正在使用 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]; });
}

如果我让我的应用在几个小时内运行,我可以在设置 > 应用 > 我的应用 > 缓存(AVD 和真实设备)中看到我的缓存从大约 160kb 增长到大约 30Mb。

那么,我是不是对设置中的缓存一无所知,还是我忘记了什么?

如果您需要其他信息,请告诉我,对不起我的英语,并提前感谢您的帮助。

最好的问候 亚历克斯

【问题讨论】:

标签: android jquery caching cordova


【解决方案1】:

清除缓存:

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

来源: Adding a splash screen and clearing cache with PhoneGap and Android

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多