Is/Can Hibernate's Second-Level Cache be Used for COUNT() operations?

拥有回忆 提交于 2019-12-13 12:29:47

问题


When using Hibernate and Ehcache as a second-level cache (2LC) implementation, is (or can) this cache used when doing COUNT operations with a WHERE clause?

In SQL terms the query I'm performing is SELECT COUNT(id) FROM table WHERE someColumn > 100. In some instances the value passed will be different each time, sometimes it will always be the same.

I'm assuming this is outside of the scope of 2LC, and instead would need to be managed 'manually' (cache the result of the query, and invalidate that cache whenever the underlying data change).


回答1:


You are right, this is beyound what L2 cache offers. However query cache will do the trick.

Basically Hibernate will cache a mapping between named parameters ([100] tuple in your example) and a query result in a cache named org.hibernate.cache.StandardQueryCache. It will also invalidate the cache when any changes are made to table (more precisely: any table that is used in a query). The last modification time of each table is stored in org.hibernate.cache.UpdateTimestampsCache cache.

See also:

  • Caching with Hibernate + Spring - some Questions!


来源:https://stackoverflow.com/questions/8712066/is-can-hibernates-second-level-cache-be-used-for-count-operations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!