2010-09-16 199 views
1

我已經通讀了幾個答案,並沒有一個工作。我在應用程序的META-INF/context.xml中放入了一個緩存。Tomcat防止靜態資源緩存

我已經在server.xml和context.xml中放了cachingAllowed ='false'。我也刪除了我的工作/ [app]緩存,這就是我看到資源回來的情況。

JSP - 看起來不錯!

請求URL:/loadconf.jsp

請求方法:GET

狀態代碼:200 OK

請求頭

接受:/

的Referer: http://localhost/

User-Agent:Mozilla/5.0(Windows; U; Windows NT 6.1;的en-US)爲AppleWebKit/534.3(KHTML,例如Gecko)鉻/ 6.0.472.59 Safari瀏覽器/ 534.3

響應頭

內容類型:應用/ JavaScript的;字符集= UTF-8

日期:星期四,2010 09月16日16點52分35秒GMT

服務器:Apache-狼/ 1.1

傳輸編碼:分塊

JS L - ooks壞

請求URL:yuiloader-DOM-event.js

請求方法:GET

狀態代碼:200 OK

請求頭

接受:/

引用者:http://localhost/

User-Agent:Mozilla/5.0(Windows; U; Windows NT 6.1; AppleWebKit/534.3(KHTML,如Gecko)Chrome/6.0.472.59 Safari/534。3

響應頭

接受-範圍:字節

緩存控制:最大年齡= 15552000

的Content-Length:60327

的Content-Type :text/javascript

日期:2010年9月16日(星期四)16: 39:57 GMT

ETag的:W/「60327-1273012296000」

到期日:星期二,2011 16點39分57秒GMT

最後所3月15日加減:星期二,04五月2010 22點31分36秒GMT

服務器:Apache-狼/ 1.1

+0

我要你點@ BalusC的出色答卷這個 http://stackoverflow.com/questions/2156077/how-can-i-disable-tomcat-caching-completly/2163381#2163381 – JoseK 2010-09-17 06:37:29

+0

我需要爲每個文件添加一個過濾器來做到這一點....爲什麼Tomcat甚至認爲這些文件應該被緩存,爲什麼說它應該被緩存xxx長。沒有指定這些參數。 – Drew 2010-09-20 16:49:16

回答

3

易於方法,使用Apache,如下所示:

# Configure Tomcat proxys 
<VirtualHost localhost:80> 

    ProxyPass/http://localhost:8080/ 
    ProxyPassReverse/http://localhost:8080/ 

    #for files that have no header 
    ExpiresDefault now 
    ExpiresByType text/javascript now 

    #overwrite the headers tomcat is foolishly trying to provide 
    Header set Cache-Control "max-age=0, must-revalidate" 
    Header set Expires "January 1, 1970" #this should be "now", but it wasn't working for me 

</VirtualHost> 

我的靜態文件現在回來200響應。