【问题标题】:how to clear cache in gwt?如何清除gwt中的缓存?
【发布时间】:2010-11-25 05:37:16
【问题描述】:

如何清除gwt中的缓存?

或者有什么方法可以阻止浏览器将缓存保留在 gwt 中?

【问题讨论】:

标签: gwt


【解决方案1】:

当您部署 GWT 应用程序时,重要的是要避免代理和浏览器缓存 GWT 生成的 .nocache.js 文件。一种解决方案是实现一个 servlet 过滤器,该过滤器添加必要的 HTTP 标头来控制缓存行为。

这是一个过滤器:http://seewah.blogspot.com/2009/02/gwt-tips-2-nocachejs-getting-cached-in.html

该示例中的标题是:

Date: Wed, 24 Nov 2010 20:32:43 GMT
Expires: Wed, 01 Nov 2000 00:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate

Date应该设置为请求的时间。

Expires 最好设置为过去的某个时间,这会迫使每个人都认为内容已经过时。

Pragma 是一个已被Cache-Control 取代的标签,但拥有它并没有什么坏处。

Cache-Control no-cache 表示浏览器或代理必须在将缓存副本发布给客户端之前重新验证它。 no-store 表示没有人保留缓存副本(这使得 no-cache 变得多余)。 must-revalidate 表示浏览器/代理必须遵守新鲜信息并重新验证,与 no-store 也是多余的。

【讨论】:

    【解决方案2】:

    当您在中间有 Apache2 服务器时,最好的方法是配置您的虚拟主机,以便始终下载 css nocache 文件。这里有一个例子:http://pgt.de/2011/01/27/apache-configuration-for-gwt-applications/comment-page-1/#comment-23996。

    把这个放在虚拟服务器文件上:

      <IfModule mod_expires.c>
         ExpiresActive On
      </IfModule>
    
      <IfModule mod_headers.c>
         <ProxyMatch (.*)nocache\.js$>
            Header Set Cache-Control "max-age=0, no-store"
         </ProxyMatch>
         <ProxyMatch (.*)\.cache\.(.*)>
            Header Set Cache-Control "max-age=31536000, public, must-revalidate"
         </ProxyMatch>
         <ProxyMatch (.*)\.cache\.js$>
            Header Set Cache-Control "max-age=31536000, private"
         </ProxyMatch>
      </IfModule>
    
     <Proxy *>
         <IfModule mod_expires.c>
            ExpiresByType application/json   "now"
            ExpiresByType text/css            "now"
            ExpiresByType text/html          "now"
         </IfModule>
         <ifModule mod_headers.c>
             Header unset ETag
             Header unset Last-Modified
         </ifModule>
         FileETag None
      </Proxy>
    

    干杯

    【讨论】:

      猜你喜欢
      • 2012-02-24
      • 2012-01-31
      • 2017-02-20
      • 2019-09-18
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 2011-05-10
      相关资源
      最近更新 更多