views:

48

answers:

2

Hello all
What is the best way to set up caching on tomcat?

Also how is caching functions?Is it url based,dir based or what?
I need url specific caching so the database don't make the same calculations for the same url's

+2  A: 

The simplest way, is to use a dedicated web cache provider. Tomcat does not have one OOTB, but you could employ Apache with mod_cache (and obviously mod_jk). In this configuration, Apache tends to act as a proxy-cache that caches the dynamic content served by Tomcat; you will have to ensure that Tomcat serves the right headers to ensure that Apache will cache the responses.

There are other commerical web-cache solutions, but they're typically used for high-end uses.

You could also employ Squid instead of Apache, to act as a reverse proxy that is also capable of serving cached content; in this case, Squid performs caching of the dynamic content.

If you do not wish to invest in an additional server, like the above solutions suggest, you might consider using EHCache to perform web page caching on Tomcat itself.

Related

  1. Java Web Application: How to implement caching techniques?
Vineet Reynolds
Thanks i already have apache as a proxy but a few attempts with mod_cache failed.Can you point me to some examples?
Argiropoulos Stavros
Well, I just noticed this link - http://blogs.sun.com/trawick/entry/caching_dynamic_content_with_apache . Hope it helps.
Vineet Reynolds
+1  A: 

Tomcat doesn't support what you want out of the box, so you'll need some extra stuff. I'm not fully aware of all mod_cache capabilities but if you're not using Apache, OSCache can do what you're requesting.

Pascal Thivent