aspose file tools*
The moose likes Struts and the fly likes How to implement cache manager in struts framework? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to implement cache manager in struts framework?" Watch "How to implement cache manager in struts framework?" New topic
Author

How to implement cache manager in struts framework?

ihate6
Greenhorn

Joined: Mar 17, 2005
Posts: 5
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?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.

Here's a good article on the subject:

http://java.about.com/library/weekly/uc_querycache1.htm


Merrill
Consultant, Sima Solutions
ihate6
Greenhorn

Joined: Mar 17, 2005
Posts: 5
thanks merrill!

will try that ..
ihate6
Greenhorn

Joined: Mar 17, 2005
Posts: 5
thanks merrill!

will try that ..
John Angel
Greenhorn

Joined: May 16, 2001
Posts: 5
Hi
Which Application server are you using ? Because if it is webpshere, it ocmes with a handy cache built in for you called Dynacache.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to implement cache manager in struts framework?
 
Similar Threads
Struts Design and Programming - different with other book
Spring, in Spring-Struts-Hibernate application
Customize jboss cache mechanism
sending email attachment with Struts?
Removing parameters from URL