2

How can I disable the static-file cache in Tomcat 8.0.23?

My app.nocache.js file created by GWT is being cached by Tomcat. Anytime I recompile, Tomcat is serving the old version of the file.

I would be happy to disable Tomcat's cache for any file containing "nocache" in it's name. Fully disabling Tomcat's cache would do as well.

I have tried:

<Resources cachingAllowed="false" cacheMaxSize="0" />

in my WEB-INF/context.xml file, or:

<Context cachingAllowed="false" cacheMaxSize="0">

...but neither of these attempts have succeeded in disabling the cache.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
Gauthier
  • 55
  • 1
  • 1
  • 10
  • 1
    are you sure that it is not your browser caching the file ? Did you clear your cache and have a look at the headers sent out from Tomcat ? – Marged May 29 '15 at 20:36
  • Yes Marged, I already checked this is not my browser caching and this is actually a tomcat cache (right file will load if I restart tomcat). Headers show method: "GET", Status code: "304 No modified" Request headers show "max-age=0" – Gauthier May 29 '15 at 21:09
  • Your question maybe have existing solutions. Comment for my answer to focus to your problem. I will edit my answer after you comment something when I have more information. – Vy Do May 30 '15 at 08:27
  • Note that a `304 Not Modified` response means "your browser has this in its cache", and if you notice, there is no content in that response. But you are right, Tomcat is still caching the static resource. Can you post your *full* `META-INF/context.xml` file? Are you sure it's being used? The configuration attributes you have in the `` element posted above are not legal and should not have been expected to work. – Christopher Schultz Jun 05 '15 at 14:08
  • See https://serverfault.com/questions/40205/how-do-i-disable-tomcat-caching-im-having-weird-static-file-problems – rogerdpack Oct 12 '17 at 17:09

2 Answers2

1

Sorry the answer is very late, may be can help other people. I found in the guide for migrating from Tomcat 7 to Tomcat 8 that you should insert the cachingAllowed and cacheMaxSize properties in the Resources tag that has to be nested in a Context tag. Could be you missed to nest it? This is the link for the official guide: https://tomcat.apache.org/migration-8.html

To me it has worked. This is what I did for my DSpace installation

<Context
    docBase="/my/path/to/xmlui"
    reloadable="true">
        <Resources cachingAllowed="false" />
</Context>

Hope this help somebody

Izerlotti
  • 76
  • 5
0

I simply changed a line in my context.xml to read <Context antiResourceLocking="false">. The default value was set to 'true' (Tomcat 8.0.39).

Lars
  • 1,311
  • 1
  • 11
  • 11