• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Me Design a Caching Solution

 
Gobind Singh
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Gobind Singh
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks I'l look into that.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic