You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joerg Endrullis <jo...@few.vu.nl> on 2008/09/16 13:13:30 UTC

disable caching of static files in tomcat 5.5

Hi,

I have a dynamically generated image "a.jpg"
and I want Tomcat to always deliver the current version.

Unfortunately Tomcat seems to have some kind of caching of static files?
Where can one disable caching of static files in Tomcat?

Why do I think Tomcat has caching of static files...

You can reproduce the problem as follows:
- create two different images x.jpg and y.jpg
- then create a symbolic link from a.jpg to x.jpg, download a.jpg,
  change the symbolic link to y.jpg, download a.jpg again:

  $ ln -s x.jpg a.jpg;
  $ wget http://localhost:8180/a.jpg?time=0;
  $ rm a.jpg;
  $ ln -s y.jpg a.jpg;
  $ wget http://localhost:8180/a.jpg?time=1

You will see that both downloaded images a.jpg.1 and a.jpg.2 are equal 
to x.jpg,
which leads to the conclusion that Tomcat uses some kind of caching.
(in order to reproduce the problem, the commands have to be
executed fast after each other, if you wait 5 seconds before the last wget,
then Tomcat returns the correct image)

Btw. it does not help to attach an artificial time-stamp to the URL:
  $ ln -s x.jpg a.jpg;
  $ wget http://localhost:8180/a.jpg?time=0;
  $ rm a.jpg;
  $ ln -s y.jpg a.jpg;
  $ wget http://localhost:8180/a.jpg?time=1
will produce identical images a.jpg?time=0 and a.jpg?time=1.

Any help would be appreciated.

Thanks,
Joerg

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
----- Original Message ----- 
From: "Joerg Endrullis" <jo...@few.vu.nl>
To: <us...@tomcat.apache.org>
Sent: Tuesday, September 16, 2008 1:13 PM
Subject: disable caching of static files in tomcat 5.5


> Hi,
>
> I have a dynamically generated image "a.jpg"
> and I want Tomcat to always deliver the current version.
>
> Unfortunately Tomcat seems to have some kind of caching of static files?
> Where can one disable caching of static files in Tomcat?
>
> Why do I think Tomcat has caching of static files...
>
> You can reproduce the problem as follows:
> - create two different images x.jpg and y.jpg
> - then create a symbolic link from a.jpg to x.jpg, download a.jpg,
>  change the symbolic link to y.jpg, download a.jpg again:
>
>  $ ln -s x.jpg a.jpg;
>  $ wget http://localhost:8180/a.jpg?time=0;
>  $ rm a.jpg;
>  $ ln -s y.jpg a.jpg;
>  $ wget http://localhost:8180/a.jpg?time=1
>
> You will see that both downloaded images a.jpg.1 and a.jpg.2 are equal to 
> x.jpg,
> which leads to the conclusion that Tomcat uses some kind of caching.
> (in order to reproduce the problem, the commands have to be
> executed fast after each other, if you wait 5 seconds before the last 
> wget,
> then Tomcat returns the correct image)
>
> Btw. it does not help to attach an artificial time-stamp to the URL:
>  $ ln -s x.jpg a.jpg;
>  $ wget http://localhost:8180/a.jpg?time=0;
>  $ rm a.jpg;
>  $ ln -s y.jpg a.jpg;
>  $ wget http://localhost:8180/a.jpg?time=1
> will produce identical images a.jpg?time=0 and a.jpg?time=1.
>
> Any help would be appreciated.
>
> Thanks,
> Joerg

Joerg, not sure here... but this is what I think is happening...
The images are been delivered to the page using ETAGS... basically they look 
at the file on disk size and modified time...
If that changes they send it, if it does change it, nothing is sent to the 
browser...

It seems to imply that symboloc links are not changing these links... but I 
dont think linux is that stupid...
So I think its just the browser hanging on.... so try this... in the main 
JSP servlet/html page do this...

response.setHeader("Cache-Control", "no-cache");
response.setHeader("Expires", "Sun, 15 Jan 1998 17:00:00 GMT");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Max-Age", 0);

In html this is all meta tags... just look em up...

Now you saying to the browser.... do not cache this page... and I'm hopng 
thats the images as well, and that ETAGS are not an issue with links...
ie if it doesnt work... linux is showing tomcat the same modified time 
(doubtful) or tomcat can detect the change of the file, and does not update 
the etag stuff... more likely... hopefully telling the whole page not to 
cache gets around it...

You have to do it all those ways because MS did their own thing... as usual 
;)

Have fun...
---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
---------------------------------------------------------------------------





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Joerg Endrullis <jo...@few.vu.nl>.
Thanks a lot, looks good, I will try that.
I tried to search, but unfortunately did not find this.

Joerg

Mark Thomas wrote:
> Joerg Endrullis wrote:
>   
>> Any help would be appreciated.
>>     
> http://www.google.co.uk/search?hl=en&q=tomcat+static+cache+configure&btnG=Search&meta=
>
> Mark
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Mark Thomas <ma...@apache.org>.
Joerg Endrullis wrote:
> Any help would be appreciated.
http://www.google.co.uk/search?hl=en&q=tomcat+static+cache+configure&btnG=Search&meta=

Mark


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Mark Thomas <ma...@apache.org>.
Epithemeus wrote:
> Thanks Mark.
> 
> I went through the documentation but the problem persists. I am using Tomcat
> 6.0 and have tried including cachingAllowed="false" in
> $CATALINA_HOME/conf/context.xml. This does not seem to work.
> 
> There is no other context.xml file currently defined in directory structure
> anywhere. Any ideas on why this still isn't working?

None. It works for me.

Are you sure it is Tomcat doing the caching?

Mark

> 
> Thanks.
> 
> 
> Mark Thomas-18 wrote:
>> Epithemeus wrote:
>>> Hi Joerg, 
>>>
>>> I am facing the same issue with Tomcat 6.0 and caching of files. I'd
>>> really
>>> appreciate it if anyone could explain how caching could be disabled.
>> Read the docs. I'd start with this:
>> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
>>
>> Mark
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Pid <pi...@pidster.com>.
On 21/05/2010 15:22, haveaguess wrote:
> 
> Ive got the same problem - did anyone figure out what is happening and why
> tomcat is caching files behind symlinks?

This thread is 9 months old.

You might consider starting a new thread, be specific about your
versions & platform.


p


> Epithemeus wrote:
>>
>> Thanks Mark.
>>
>> I went through the documentation but the problem persists. I am using
>> Tomcat 6.0 and have tried including cachingAllowed="false" in
>> $CATALINA_HOME/conf/context.xml. This does not seem to work.
>>
>> There is no other context.xml file currently defined in directory
>> structure anywhere. Any ideas on why this still isn't working?
>>
>> Thanks.
>>
>>
>> Mark Thomas-18 wrote:
>>>
>>> Epithemeus wrote:
>>>> Hi Joerg, 
>>>>
>>>> I am facing the same issue with Tomcat 6.0 and caching of files. I'd
>>>> really
>>>> appreciate it if anyone could explain how caching could be disabled.
>>>
>>> Read the docs. I'd start with this:
>>> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
>>>
>>> Mark
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>>
>>
>>
> 



Re: disable caching of static files in tomcat 5.5

Posted by haveaguess <be...@rbs.com>.
Ive got the same problem - did anyone figure out what is happening and why
tomcat is caching files behind symlinks?


Epithemeus wrote:
> 
> Thanks Mark.
> 
> I went through the documentation but the problem persists. I am using
> Tomcat 6.0 and have tried including cachingAllowed="false" in
> $CATALINA_HOME/conf/context.xml. This does not seem to work.
> 
> There is no other context.xml file currently defined in directory
> structure anywhere. Any ideas on why this still isn't working?
> 
> Thanks.
> 
> 
> Mark Thomas-18 wrote:
>> 
>> Epithemeus wrote:
>>> Hi Joerg, 
>>> 
>>> I am facing the same issue with Tomcat 6.0 and caching of files. I'd
>>> really
>>> appreciate it if anyone could explain how caching could be disabled.
>> 
>> Read the docs. I'd start with this:
>> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
>> 
>> Mark
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/disable-caching-of-static-files-in-tomcat-5.5-tp19509596p28634513.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Epithemeus <ep...@googlemail.com>.
Thanks Mark.

I went through the documentation but the problem persists. I am using Tomcat
6.0 and have tried including cachingAllowed="false" in
$CATALINA_HOME/conf/context.xml. This does not seem to work.

There is no other context.xml file currently defined in directory structure
anywhere. Any ideas on why this still isn't working?

Thanks.


Mark Thomas-18 wrote:
> 
> Epithemeus wrote:
>> Hi Joerg, 
>> 
>> I am facing the same issue with Tomcat 6.0 and caching of files. I'd
>> really
>> appreciate it if anyone could explain how caching could be disabled.
> 
> Read the docs. I'd start with this:
> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
> 
> Mark
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/disable-caching-of-static-files-in-tomcat-5.5-tp19509596p24867271.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Mark Thomas <ma...@apache.org>.
Epithemeus wrote:
> Hi Joerg, 
> 
> I am facing the same issue with Tomcat 6.0 and caching of files. I'd really
> appreciate it if anyone could explain how caching could be disabled.

Read the docs. I'd start with this:
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Epithemeus <ep...@googlemail.com>.
Hi Joerg, 

I am facing the same issue with Tomcat 6.0 and caching of files. I'd really
appreciate it if anyone could explain how caching could be disabled.

Many thanks!


Christopher Schultz-2 wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Joerg,
> 
> Joerg Endrullis wrote:
>>  $ ln -s x.jpg a.jpg;
>>  $ wget http://localhost:8180/a.jpg?time=0;
>>  $ rm a.jpg;
>>  $ ln -s y.jpg a.jpg;
>>  $ wget http://localhost:8180/a.jpg?time=1
> 
> My brain hurts. How about:
> 
> $ wget -O t0.jpg http://localhost:8180/a.jpg?time=0
> $ wget -O t1.jpg http://localhost:8180/a.jpg?time=1
> 
> ...and then compare the two.
> 
>> You will see that both downloaded images a.jpg.1 and a.jpg.2 are equal
>> to x.jpg,
> 
> Er, where did a.jpg.1 and a.jpg.2 come from? I think you are confusing
> yourself with the symlinks, wget, etc. even if Tomcat does have a
> problem. Simplifying your process will surely help.
> 
> Is a.jpg changing on the server at some point? You say this is a static
> resource, but you never specified that you were changing the remote file
> at all. When/how does that happen?
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkjRey0ACgkQ9CaO5/Lv0PAUvgCgi7ziGeHwW9LMGocay39egavO
> a4gAoLX5EmwTEcKbZnwK+bXOUl4nzEB+
> =mdAN
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/disable-caching-of-static-files-in-tomcat-5.5-tp19509596p24848333.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: disable caching of static files in tomcat 5.5

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joerg,

Joerg Endrullis wrote:
>  $ ln -s x.jpg a.jpg;
>  $ wget http://localhost:8180/a.jpg?time=0;
>  $ rm a.jpg;
>  $ ln -s y.jpg a.jpg;
>  $ wget http://localhost:8180/a.jpg?time=1

My brain hurts. How about:

$ wget -O t0.jpg http://localhost:8180/a.jpg?time=0
$ wget -O t1.jpg http://localhost:8180/a.jpg?time=1

...and then compare the two.

> You will see that both downloaded images a.jpg.1 and a.jpg.2 are equal
> to x.jpg,

Er, where did a.jpg.1 and a.jpg.2 come from? I think you are confusing
yourself with the symlinks, wget, etc. even if Tomcat does have a
problem. Simplifying your process will surely help.

Is a.jpg changing on the server at some point? You say this is a static
resource, but you never specified that you were changing the remote file
at all. When/how does that happen?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjRey0ACgkQ9CaO5/Lv0PAUvgCgi7ziGeHwW9LMGocay39egavO
a4gAoLX5EmwTEcKbZnwK+bXOUl4nzEB+
=mdAN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org