有没有办法让我找出哪些类(即哪些不同类型的实例)被缓存在hibernate二级缓存中。
最佳答案
二级缓存不缓存实体的实例,它缓存实体的“脱水”版本。这在blog post中有很好的解释。 :
The 2nd level cache
The hibernate cache does not store instances of an entity - instead Hibernate uses something called dehydrated state. A dehydrated state can be thought of as a deserialized entity where the dehydrated state is like an array of strings, integers etc and the id of the entity is the pointer to the dehydrated entity. Conceptually you can think of it as a Map which contains the id as key and an array as value. Or something like below for a cache region:
{ id -> { atribute1, attribute2, attribute3 } } { 1 -> { "a name", 20, null } } { 2 -> { "another name", 30, 4 } }
If the entity holds a collection of other entities then the other entity also needs to be cached. In this case it could look something like:
{ id -> { atribute1, attribute2, attribute3, Set{item1..n} } } { 1 -> { "a name", 20, null, {1,2,5} } } { 2 -> { "another name", 30, 4, {4,8} } }
根据您使用的二级缓存提供程序,您可能会获得一些控制台来监视/浏览缓存,但您仍然看不到“实例”。
资源
关于java - hibernate中二级缓存中缓存了哪些类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3715301/