I am using JDBC. I have database intensive computations, and I would like to cache the results.
I am using HashMap<String, ResultSet> to cache the results. However, the program often gives OutOfMemory Exception because the cache gets too large.
Any advice about a better data structure/caching interface to use?
First, don’t cache the
ResultSet, create some domain objects with the data and then cache them.Second, use some kind of caching framework that evicts old entries that are not used. My favorite is Guava Cache for it’s easy configuration in code, but another popular one is Ehcache.