4

我使用的是捆绑了 EHCache 1.5 的 Hibernate 3.5.1。

如果我想使用最新的 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>

那会奏效吗?一些文档似乎暗示为每个映射类创建一个单独的区域/缓存......

谢谢。

4

2 回答 2

2

如果我想使用最新的 EHCache 版本(2.0.1),是否只是从我的项目中删除 ehcache-1.5.jar 并替换为 ehcache-core-2.0.1.jar 的问题?有什么需要注意的问题吗?

根据关于使用 Ehcache 作为Hibernate Second Level Cache的 Ecache 文档,您确实必须使用 ehache-core.jar 并且还要更改Hibernate 的配置

另外 - Hibernate 映射文件中的缓存“区域”是否与 ehcache 配置 xml 中的缓存“名称”相同?

是的。同样,请参阅文档,这在配置 ehcache.xml中进行了说明。

那会奏效吗?一些文档似乎暗示为每个映射类创建一个单独的区域/缓存

该文档并不暗示,它在缓存映射中以黑白方式书写,这是默认设置:

region (optional: defaults to the class or collection role name): specifies the 
name of the second level cache region 

它会起作用吗?从技术上讲,是的。这是个好主意吗?我不确定。IMO 最好在 Hibernate 和 Ehcache 级别都有更细粒度的区域(特别是如果您计划使用分布式缓存和失效策略,您当然不想使所有实体失效)。我会使用 Hibernate 的默认值。

于 2010-04-24T14:55:57.527 回答
0

如果您使用的是maven,我遇到了同样的问题。

最好防止hibernate自行下载ehcache并提供您的ehcache条目。

IE

        <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.6.ga</version>
        <exclusions>
            <exclusion>
                <groupId>net.sf.ehcache</groupId>
                <artifactId>ehcache</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

这样它就不会下载内部 ehcache 在我的情况下它是版本 1.2.3

然后放

        <dependency>
        <groupId>net.sf</groupId>
        <artifactId>ehcache-core</artifactId>
        <version>2.4.2</version>
    </dependency>

在你的 POM.xml

它应该工作。

于 2013-02-25T07:52:43.883 回答