简体   繁体   中英

Which Classes are Cached in second level cache in hibernate

有没有办法让我找出休眠的二级缓存中缓存了哪些类(即不同类型的实例)。

The second level cache doesn't cache instances of entities, it caches a "dehydrated" version of entities. This is well explained in this 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} } } 

Depending on the L2 cache provider you're using, you might get some console to monitor/browser the cache but, still, you won't see "instances".

Resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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