• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to implement cache manager in struts framework?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ihate6
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks merrill!

will try that ..
 
ihate6
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks merrill!

will try that ..
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Which Application server are you using ? Because if it is webpshere, it ocmes with a handy cache built in for you called Dynacache.
 
reply
    Bookmark Topic Watch Topic
  • New Topic