views:

360

answers:

2

I am a .Net developer who is starting to do more and more Java development at work. I have a specific question about caching that I hope you guys can solve or offer suggestions. We are starting a java project that will be deployed on a Linux box running JBoss. We are planning ahead and try to think about our caching strategy. One thing we would like to do is to output cache the pages since our content will likely be cacheable for 8 hours or so. I started looking at mod_cache and this does what we want to do. The one other requirement that I need to meet is that for every request, I need to do some custom logging. I need the basic request URL and then some other business logic stuff and stuff it into a database. My questions are these:

1) How can i put code at the mod_cache level to kick off the custom logging process?
2) I want to queue these logging messages up somehow since i don't want to go to the db with every request. What would be the best way to tackle this?

I would appreciate any suggestions or solutions if you got 'em!

+1  A: 

I assume your planned setup is Apache httpd -> mod_cache -> mod_proxy/mod_jk -> JBoss

1) You can't, since mod_cache at the Apache level does not even get down to calling Java. Hence, you would need to check if mod_cache itself has some logging facility which you can hook something in, or you would need to modify mod_cache and recompile it. This has nothing to do with Java and I don't think you can do it in Java.

2) Again, this is not a Java question when mod_cache is handling the response on its own without calling JBoss.

JBoss/Catalina/Tomcat are pretty fast when it comes down to delivering pages rendered by JSPs or other web frameworks. Set the cache expiration date and let the browser handle the cache.

mhaller
A: 

You might look into using memcached instead. I don't know if there is a Tomcat/JBoss wrapper module for this program or not. It will let you cache just about any data that you can serialize and make a string key value for.

You have to write an accessor for what you need, which tries to pull stuff out of the memcached process, and/or calls a generator function upon cache miss (as well as caching the generator's result). Within this accessor, you could log cache hits and misses.

The memcached daemon is written in C, of course, so it won't "mark and sweep" itself to death holding onto data, unlike java (or most of the other "modern" language runtimes).

On the other hand, maybe mod_cache has some logging hooks. Maybe you should look into that, as this will lighten the load on your java process.

Is this close to the sort of thing you are looking for?

Roboprog