Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to cache a collection of values

 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I call a stored procedure that returns about 9000 rows of information which consist of a part number and part description that I use to populate a dropdown select box in a form.

Instead of calling the procedure and returning 9000 rows each time the page is displayed, how can I cache this collection of values that gets returned to my jsp page?

Someone mentioned that I use a servicelocator and singleton pattern to solve the problem. Is this the proper way to accomplish my goal of caching the returned collection? Are there better ways to do this?

Any thoughts would be great!

Thanks,
Dave
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yes, we used ServiceLocator pattern with Singleton collection object to achieve the same.

But when you do this you have to be aware of two things.

First, when you return the collection through the exposed API, you return a cached unmodifiable collection, so that if nobody can change the content of the collection. Used the unmodifiableXXX method of java.util.Collections class to make the collection unmodifiable.

Second, if there is scope for change in underlying database, you have to provide a means to update your cached data.

Susanta
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to check out my TtlReference class from this topic. It will allow you to cache the collection, but the reference will "time out" after a set period of time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic