Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I got an Apache Tomcat 7 server. If I change a file on the server (for example stylesheet, javascript file or any plain/text file), for example using vim. Then if I go to the file in an internet browser, and press F5 a few times till I see the actual change, I have to wait (while pressing F5 every 500 ms) a few seconds (~3 seconds) before I see what I just changed.

Thus in short: if a file is changed on the server, I see it ~3 seconds later client side. So somewhere there has to be a cache, probably server side since I use F5 which should discard client side cache. So how can I setup a directory on my Apache Tomcat server so that it will not cache files?

I want to do this because I created a simple Ajax/Servlet based website to chat. But after typing a message, it will appear ~3 secs later. I know this can be way faster, because I have done it before on a PHP free webhost server.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

Tomcat caches static content with a TTL of 5 secs by default. If you want to change that see http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Attributes. Specifically you want cacheTTL, cachingAllowed and maybe cacheMaxSize and cacheObjectMaxSize.

share|improve this answer
add comment

Not sure how Tomcat adds the no cache to everything. The easy way to control the headers yourself is to write and configure a generic header filter in web.xml as follows:

=== web.xml ===

NoCache x.y.z.filters.ResponseHeaderFilter

Cache-Control no-cache, must-revalidate

CacheForWeek uk.co.slc.crm.common.filters.ResponseHeaderFilter

Cache-Control max-age=604800, public

NoCache /*.do

CacheForWeek /images/*

CacheForWeek /*.js

CacheForWeek /*.css

=== web.xml ===

share|improve this answer
    
Sorry if my question was not clear, but my question is about server side caching, not client side! –  Yeti May 3 '12 at 15:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.