wood burning stoves 2.0*
The moose likes Servlets and the fly likes Help Me Design a Caching Solution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help Me Design a Caching Solution" Watch "Help Me Design a Caching Solution" New topic
Author

Help Me Design a Caching Solution

Gobind Singh
Ranch Hand

Joined: Aug 04, 2006
Posts: 62
I have J2EE web application. The application is a reporting application i.e. it does the following:

1.user selects a report from the menu
2.the prompts for that report appear on the screen
3.User answers the prompts and clicks sumbit
4.Servlet reads in the prompt answers as request parameters and runs a query based on the prompt answers
5.The results of the query are displayed in a html table in a jsp

My problem is that a lot of the prompts are drop down lists which are populated by connecting to the datasource, running a query and populating a html <SELECT>. Some of these drop down prompts are quite big and the queries take long to execute.

What I want to do is to be able to cache the prompts i.e If the prompt has been presented to the any user (for the duration of the servlet context) before, then dont go away to the database and repopulate the drop down list. Instead obtain the drop down list from sort of prompt cache.

I would also need the (admin)functionality to be able to clear the prompt cache at any time since the underlying data for some of the prompts gets refreshed after a few days.

Any ideas appreciated!
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
Check OSCache OSCache from Opensymphony.

SCache is a caching solution that includes a JSP tag library and set of classes to perform fine grained dynamic caching of JSP content, servlet responses or arbitrary objects...


- SCEA, SCJD, SCBCD, SCWCD, SCMAD, SCJP, ICAD (WebSphere), Lotus Principal CLP, Lotus CLP, Lotus CLS
Gobind Singh
Ranch Hand

Joined: Aug 04, 2006
Posts: 62
thanks I'l look into that.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I really do not feel that you should be going for a full fledged cache for your purpose.From your post I can get that you need a very simple kind of cache.I would suggest you to go for a home grown cache ,rather going for a full blown as most of the features of that would be unused.

You can use a simple singleton class as your cache manager.And a hashtable as the datastructure for your cache.And about clearing the cache , you can expose the cache manager using an MBean interface for clearing the cache at your will.

Key to the hashtable can be the drop down option and value can be the value from the database.If there are multiple data that you query to database and send to user as jsp , then you might create a bean class for all the data.


Rahul Bhattacharjee
LinkedIn - Blog
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Seems to me that although a simple home-grown cache sounds attractive, it may not do for an app that runs for a long time or if the underlying database changes.
At a minimum, cached data should time-out and there should be a mechanism to trim the cache if it takes too much memory. Whirlycache is an active project you might consider.
Bill
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
That is the reason I have asked to expose the configuration parameters using an mbeab.And for time to time refreshing of data we can have a thread to do that.
But as now the requirement grows complicated , you might consider a third party cache.
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

If you are going for third party cache, Look at swarm cache. it has lots of other advantage like IP multi cast which will not allow cache to have stale data.

Have a look at HERE.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help Me Design a Caching Solution
 
Similar Threads
JSP To Servlet
updating drop down list boxes
How to populate default textarea value on select from dropdown
Drop down list value
Displaying record from combo box