PDA

View Full Version : (Static) caching


chrisjo
Mar 16th, 2006, 01:35 PM
I'm starting an application whose data is kinda intensive to process, and it doesn't change very often (everything from every couple of hours to once a day).

How do I go about to implement a full cache of a page? After the cache has been built I would like the controller to just throw back a static page, not forwarding to jsp or making any database calls. In other words a fully cached page should involve close to no processing. I'd rather not pregenerate all the pages since there are some pages that refresh more othen than others and so on. Is this possible, and if so can anyone point me in the right direction?

kenevel
Mar 16th, 2006, 02:36 PM
You could always try OSCache, available from http://www.opensymphony.com/oscache/.

This provides JSP tags you can wrap around the content you want cached.

Mike

chrisjo
Mar 16th, 2006, 02:41 PM
Thanks for that. But if it provides tags to be used in the JSP I've only come half the way. By the time the requests goes in for processing in the JSP it may already have contacted the database and done processing which wouldn't be needed if the whole page had been cached. I want to do something like this in my controller:


if (page.isCached()) {
displayCachedData();
return null;
}

// not cached, fetch from db, process, return ModelAndView

gparker
Mar 16th, 2006, 03:49 PM
You can use the CacheFilter of OSCache. It will get the cached page, before it even gets to the controller.

http://www.opensymphony.com/oscache/wiki/CacheFilter%20Tutorial.html

chrisjo
Mar 16th, 2006, 04:46 PM
Excellent, I'm about to love oscache! :) Thanks!