开发者

how to clear cache in gwt?

开发者 https://www.devze.com 2023-01-27 01:42 出处:网络
How can I clear the cache in gwt? or is there any way that prevent browser to keep the cach开发者_JAVA百科e in gwt?When you deploy a GWT-application it\'s important to avoid proxies and browsers to c

How can I clear the cache in gwt?

or is there any way that prevent browser to keep the cach开发者_JAVA百科e in gwt?


When you deploy a GWT-application it's important to avoid proxies and browsers to cache the .nocache.js-files generated by GWT. One solution is to implement a servlet filter that adds the necessary HTTP-headers that control the caching behaviour.

Here's such a filter: http://seewah.blogspot.com/2009/02/gwt-tips-2-nocachejs-getting-cached-in.html

The headers in that example are:

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 should be set to the time of the request.

Expires is best set to sometime in the past, this forces everyone to consider the content already stale.

Pragma is a tag that has been superseded by Cache-Control, but it doesn't hurt to have it.

Cache-Control no-cache means a browser or proxy must revalidate a cached copy before releasing it to the client. no-store means no one is ever keeping a cached copy (which makes no-cache redundant). must-revalidate says the browser/proxy must obey freshness information and revalidate, also redundant with no-store.


The best way to do it when you have an Apache2 server in the middle is configuring your Virtual Host in order to download css nocache files always. Here you have an example: http://pgt.de/2011/01/27/apache-configuration-for-gwt-applications/comment-page-1/#comment-23996.

Put this on the Virtual Server file:

  <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>

Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消