7

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

Also how caching works?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

4
  • Are you intending to cache the HTTP responses from the server for a given URL with the same querystring or POST parameters? Commented Sep 28, 2010 at 14:51
  • you might want to update the question to state that. I think people might misunderstand the question and it might be closed. Commented Sep 28, 2010 at 14:58
  • @Vineet Reynolds Sorry i misunderstood you probably.Are you talking for browser caching?Because i'm talking for server caching Commented Sep 28, 2010 at 15:03
  • I was referring to server-side caching employed in the data center. Commented Sep 28, 2010 at 15:07

3 Answers 3

11

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?
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks i already have apache as a proxy but a few attempts with mod_cache failed.Can you point me to some examples?
Well, I just noticed this link - blogs.sun.com/trawick/entry/caching_dynamic_content_with_apache . Hope it helps.
2

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.

Comments

1

Can you use the Expires Filter?

http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter

See also this question:

Enable caching in Tomcat 6?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.