简体   繁体   English

Java缓存查询结果

[英]Java Cache Query Results

I am using JDBC. 我正在使用JDBC。 I have database intensive computations, and I would like to cache the results. 我有数据库密集型计算,我想缓存结果。

I am using HashMap<String, ResultSet> to cache the results. 我正在使用HashMap<String, ResultSet>来缓存结果。 However, the program often gives OutOfMemory Exception because the cache gets too large. 但是,由于缓存太大,该程序通常会发出OutOfMemory异常。

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. 首先,不要缓存ResultSet ,使用数据创建一些域对象,然后再缓存它们。

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 . 我最喜欢的是Guava Cache,因为它易于在代码中进行配置,但另一个受欢迎的是Ehcache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM