cache instances of objects in a web application

I’m (perennially) working on tonight, putting the final touches on the application. I’d running into a couple places on the site where performance is not so good so I’d like to start caching objects, presumably in the servlet container. I’m looking for ‘the way’ to cache instances of objects in a web application. I found this article on, which seems promising, but doesn’t relate caching to a servlet container. Would you just place the hashtable in the ServletContext using setAttribute()?

JCACHE – Java Temporary Caching API looks promising as well, although I don’t see where JCACHE lives.. anyone else know if JCACHE is alive and well?

I remember going to a presentation on caching at JavaOne last year, one of the presentations was on ESI, but of course, they have nothing to download on that site, so it’s worthless.

2 thoughts on “cache instances of objects in a web application”

  1. Hey AJ,

    I find that rather than having a central “cache” it’s often easier to have the factories of expensive-to-load objects (you’re using factories, right? 😉 ) do their own pooling. In other words, keep a hashtable internal to your RecipeFactory that holds up to “x” recipes. Course I’m making a lot of assumptions about your app… but if you can get away with caching this way, it hides away a lot of complexity.

    Or from the completely opposite direction, if you cache the HTML in the JSP layer, there are some good taglibs out there for that…

    That JavaWorld article looks good, but for a low-traffic site, auto-expiring cache entries may not do as much good as having a fixed-size cache and manual invalidation.

    I’m looking forward to JCACHE too, the only implementations I know of are Oracle (who I believe invented the API, to make their own appserver rock BEA/WebSphere in the benchmarks) and SpiritSoft, and both are very proprietary.


  2. Oh, forgot to mention that I believe JCACHE is only a big win if your app is distributed and you need the different JVM’s to have a perfectly consistent view of the data. I’m guessing you only have one server and even if you had several it’d probably be ok for the data to get a *little* stale, considering the nature of the site.

Leave a Reply

Your email address will not be published. Required fields are marked *