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?
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.