jQuery实际上不会为您缓存请求-当您设置cache为时false,它只是设置一些标头并传递“缓存无效化”查询字符串变量(例如,?_=487262189472),以防止浏览器或任何代理返回缓存的响应。
如果您想要10分钟的缓存,则可以轻松实现自己的缓存。例如,
var cacheBuster = new Date().getTime();
setInterval(function() {
cacheBuster = new Date().getTime();
}, 1000 * 60 * 10)
Run Code Online (Sandbox Code Playgroud)
然后,只需在查询字符串变量中将其添加到您的请求中即可(例如,?_noCache=<cacheBuster>)。
编辑:为了使它成为一个更完整的解决方案,下面是一个示例,该示例说明如何cacheBuster在所有jQuery Ajax请求上透明地对实际Ajax调用使用:
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
var startChar = options.url.indexOf('?') === -1 ? '?' : '&';
options.url += startChar + '_noCache=' + cacheBuster;
});
Run Code Online (Sandbox Code Playgroud)