our application currently takes input from user, and using those as search parameters, returns a list of things from the database matching the criteria. Now we have to implement the cache manager, and store the previous search results and display them if the same search parameters are entered.
Can some one provide information on how this can be done and if its different when the application is in a struts framework?
As I see it, setting up a caching mechanism has very little to do with the struts framework. It's primarily a function of the model, whereas struts components deal more with the view and the controller portion of MVC architecture.
There are lots of ways to set up a cache. Here's one very simple one:
Create a class that follows the singleton pattern, where the the only way to instantiate it is through the getInstance() method.
You would then set up a way to store the queries. I'd suggest using one of the Map classes in java.util.
The key portion of the map would be the query, and the value would be a List of the rows returned from the query.
Whenever a user submits a query, you'd first check to see if it existed in the Map. If it does, you'd just return the List without going to the database. If it doesn't, execute the query, put the results in the Map, and return the result.
You would want to set up some sort of mechanism to flush out the older or unused queries. Otherwise it could start eating up too much memory.