开发者

caching sql result set in java

开发者 https://www.devze.com 2023-01-28 00:51 出处:网络
I know that caching 开发者_开发知识库the resultset of frequently used sql statements is better for the performance I am searching about the best way to cache sql result set in java. I found some codes

I know that caching 开发者_开发知识库the resultset of frequently used sql statements is better for the performance I am searching about the best way to cache sql result set in java. I found some codes but, it requires adding new jar files to netbeans. Can anybody help me how can do that without needing to additional apis?


You should cache the resulting objects, not the result sets, because the ResultSet has a reference to the connection (via the statement) which often hold an open database connection or is no longer usable after the connection has been closed!


You should cache the data only. I would advise you to use an external api because you will probably also need to evict old data from cache(to prevent from using to much memory).

Using guave:

ConcurrentMap _continueContexts = new MapMaker() .expiration(10, TimeUnit.SECONDS) .makeMap();

P.S: You should something like maven to manage your dependencies.


You could make a linked list of results. With the cache trigger pointing to the start of the list. Since linked lists act like a wrapper around whatever you want you can make the results as generic as you want. This won't require another api but you will have to implement this all on your own and hopefully you understand why we don't like reinventing the wheel.

0

精彩评论

暂无评论...
验证码 换一张
取 消