如何清除与WinJS.xhr关联的缓存?

时间:2013-01-26 19:02:58

标签: caching windows-8 visual-studio-2012 xmlhttprequest winjs

我正在使用WinJS库和Visual Studio 2012(Update 1)在Windows 8上进行应用程序开发,并且遇到了WinJS.xhr缓存来自外部REST API的响应的困难我从我的内部查询应用

通过修改服务器以将“Expires”标头设置为值“0”来发送响应,我部分解决了这个问题。

但是,在我修改服务器的响应标头之前,仍有旧的响应卡在缓存中,现在可以追溯到两天。我无法弄清楚如何清除与WinJS.xhr相关的缓存 - 是否有一种编程方式可以做到这一点?隐藏在Visual Studio中的选项/工具?

1 个答案:

答案 0 :(得分:0)

使用If-Modified-Since标头发送请求,如下所示:

WinJS.xhr({ 
    url: "http://www.microsoft.com",
    headers: {
        "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT"
    } })
    .done(function complete(result) {
        // Report download.
        xhrDiv.innerText = "Downloaded the page";
        xhrDiv.style.backgroundColor = "#00FF00";
});

关闭If-Modified-Since页面后,会找到其他标题here。重要的是CACHE-CONTROL标题。来自here的其他缓存指令包括:

Cache-Control   = "Cache-Control" ":" 1#cache-directive

cache-directive = cache-request-directive
     | cache-response-directive

cache-request-directive =
       "no-cache"                          ; Section 14.9.1
     | "no-store"                          ; Section 14.9.2
     | "max-age" "=" delta-seconds         ; Section 14.9.3, 14.9.4
     | "max-stale" [ "=" delta-seconds ]   ; Section 14.9.3
     | "min-fresh" "=" delta-seconds       ; Section 14.9.3
     | "no-transform"                      ; Section 14.9.5
     | "only-if-cached"                    ; Section 14.9.4
     | cache-extension                     ; Section 14.9.6

 cache-response-directive =
       "public"                               ; Section 14.9.1
     | "private" [ "=" <"> 1#field-name <"> ] ; Section 14.9.1
     | "no-cache" [ "=" <"> 1#field-name <"> ]; Section 14.9.1
     | "no-store"                             ; Section 14.9.2
     | "no-transform"                         ; Section 14.9.5
     | "must-revalidate"                      ; Section 14.9.4
     | "proxy-revalidate"                     ; Section 14.9.4
     | "max-age" "=" delta-seconds            ; Section 14.9.3
     | "s-maxage" "=" delta-seconds           ; Section 14.9.3
     | cache-extension                        ; Section 14.9.6

来自here

  

有时用户代理可能想要或需要坚持缓存   使用原始服务器重新验证其缓存条目(而不仅仅是   沿着原始服务器的路径的下一个缓存),或重新加载它   来自原始服务器的缓存条目。端到端的重新验证可能是   如果缓存或原始服务器高估了,则必需   缓存响应的到期时间。端到端重新加载可能是   如果缓存条目由于某种原因而被破坏,则是必需的。

  

特定的端到端重新验证

     

请求包含“max-age = 0”缓存控制指令,   它强制每个缓存沿着原始服务器的路径重新生效   具有下一个缓存或服务器的自己的条目(如果有)。最初的   请求包括客户端的缓存验证条件   目前的验证人。

相关问题