This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to implement cache manager in struts framework?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
thanks merrill!

will try that ..
 
ihate6
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks merrill!

will try that ..
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
I was her plaything! And so was this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic