简体   繁体   English

如何为对象和集合使用hibernate二级缓存

[英]how to use hibernate second level cache for objects and collections

i have 3 classes 我有3节课

class A{
    List<B> child;
}

class B{
    List<C> child;
}

class C{
    String name;
}

in my application, class A will load by any request from users. 在我的应用程序中,A类将根据用户的任何请求加载。 am i should to use @Cache annotation above any classes? 我应该在任何类之上使用@Cache注释吗? Should I use it above Lists or just put it above class A? 我应该在列表上方使用它还是将它放在A类之上?

Hibernate has different regions for caching. Hibernate有不同的缓存区域。 If you want to cache a has-many collection, you can (ie the children for class B ), but then the class that makes up the collection needs to be Cached as well. 如果你想缓存一个has-many集合,你可以(即B类的children ),但是组成集合的类也需要缓存。 Ultimately it comes down to what you need and what you want to cache. 最终,它归结为您需要的内容以及您想要缓存的内容。

So in your case you could cache any of the classes, and in addition, any of the List 's as well. 所以你的情况,你可以缓存任何类的,此外,任何List的为好。 Whether or not it makes sense to do so will probably require some load testing. 这样做是否有意义可能需要进行一些负载测试。

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

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