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.
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.
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
Joined: Nov 29, 2005
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.