我使用的是 Hibernate 3.5.1,它与 EHCache 1.5 捆绑在一起。
如果我想使用最新的 EHCache 版本 (2.0.1),是否只需从我的项目中删除 ehcache-1.5.jar 并替换为 ehcache-core-2.0.1.jar?有什么需要注意的问题吗?
此外 - Hibernate 映射文件中的缓存“区域”是否与 ehcache 配置 xml 中的缓存“名称”相同?我想要做的是定义 2 个命名缓存区域 - 一个用于不会更改的只读引用实体(查找列表等),一个用于所有其他实体。所以在ehcache中我想定义两个元素;
<cache name="readonly"> ... </cache>
<cache name="mutable"> ... </cache>
然后在我的 Hibernate 映射文件中,我将指定用于每个实体的缓存:
<hibernate-mapping>
<class name="lookuplist">
<cache region="readonly" usage="read-only"/>
<property> ... </property>
</class>
</hibernate-mapping>
那行得通吗?一些文档似乎暗示为每个映射类创建一个单独的区域/缓存...
谢谢。
最佳答案
If I want to use the latest EHCache release (2.0.1), is it just a matter of removing the ehcache-1.5.jar from my project, and replacing with ehcache-core-2.0.1.jar? Any issues to be aware of?
根据关于将 Ehcache 用作 Hibernate Second Level Cache 的 Ecache 文档, 你必须使用 ehache-core.jar 确实而且要改变 Hibernate's configuration .
Also - is a cache "region" in the Hibernate mapping file that same as a cache "name" in the ehcache configuration xml?
是的。再次引用文档,这在 Configuring ehcache.xml 中有解释。 .
Will that work? Some of the documentation seems to imply that a separate region/cache gets created for each mapped class
文档没有暗示,它在Cache mappings 中白纸黑字地写着这是默认值:
region (optional: defaults to the class or collection role name): specifies the
name of the second level cache region
它会起作用吗?从技术上讲,是的。这是个好主意吗?我不确定。 IMO 最好在 Hibernate 和 Ehcache 级别上拥有更细粒度的区域(特别是如果您计划使用分布式缓存和失效策略,您当然不希望使所有实体失效)。我会使用 Hibernate 的默认值。
关于java - HIbernate 3.5.1 - 我可以直接加入 EHCache 2.0.1 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2703933/