• 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

Caching data base results

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am developing a tool for my team. This a tool which is used for monitoring purpose(restricted explanation). Even if "n" number of users are logged to the system, the data displayed to the users will be same irrespective of the users. These details are queried from the database and displayed to the user. But this data is not static always. This will be changing each one hour. Means, in the back end a scheduler is running which is updating the DB in every hour.

So, for a particular period of time (maximum 1 hour), the data will be constant. As per the current design, for each user i am querying the DB and displaying the details. This is nothing more than performance reduction.

I am using JSP to display the details. Is there any mechanism to query the db and put the data in cache or some where else(this should get updated in each hour) so that i can use those values without having a db connection?

Note : I do not want the details to be stored in text,xml,CSV etc.

Please let me know if you need further details.

Thanks
Seby
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seby,

You can simply implement a caching mechanism yourself. Search for Implementing Caching in google. This singleton class cache you can store in Application context , thus it will be accessible from any user login.
Or rather than storing in context you can just make it a singleton class initialized in a separate Servlet (Call it a ApplicationInitializerServlet) which gets loaded up when application is loaded in Servlet container.
In the cache class you can create a Thread (You can use a Schedulre or timer class or New ThreadExecutor class in java 5) to create a scheduler thread which will keep on looing for any change in the particular DB you are expecting data to change , As soon as it finds new updates in DB yuor thread can invoke JDBC calls to update the cache class object.

You can use HashMap or HashTable as per your convenience.

Also if you want you can use Hibernate to do all this caching and periodic lookup of database change. It relieves you of creating a continuous running thread to monitor DB change. As soon as any table data changes the Hibernate cache objcets are updated on their own.

but i will advise avoid Hibernate for this small requirement and create your own Cache classes.

Hope this helps
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no need to re-invent caching. There are some perfectly good pre-built (and pre-debugged) resources at jakarta.apache.org. In fact, I think that you'll find them being used as the caching mechanism for both open-source ORM products like Hibernate and commercial ones.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic