gpt4 book ai didi

hibernate - 为什么 EhCacheProvider 被弃用?

转载 作者:行者123 更新时间:2023-12-02 19:19:28 26 4
gpt4 key购买 nike

我正在将我的 hibernate 项目配置为使用二级缓存提供程序,以便我可以利用查询缓存。

我添加了对ehcache的依赖:

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

我认为我想要使用的提供程序类是:

net.sf.ehcache.hibernateEhCacheProvider

当我在 Eclipse 中查看引用的库时,我在 EhCacheProviderSingletonEhCacheProvider 上看到了 @Deprecated 注释。是什么赋予了?我可以使用最新的替代提供商吗?

我正在使用 hibernate 版本 3.4.0.GA,以防万一。

最佳答案

What gives? Is there an up-to-date replacement provider that I can use?

它们已被弃用,取而代之的是通过其 CacheRegionFactory 实现新 Hibernate 3.3/3.5 SPI 的类。这些实现分别是:

  • net.sf.ehcache.hibernate.EhCacheRegionFactory
  • net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory

新 SPI 的优势包括:

  • The SPI removed synchronization in the Hibernate cache plumbing. It is left up to the caching implementation on how to control concurrent access. Ehcache, starting with 1.6, removed syncrhonization in favour of a CAS approach. The results, for heavy workloads are impressive.
  • The new SPI provides finer grained control over cache region storage and cache strategies. Ehcache 2.0 takes advantage of this to reduce memory use. It provides read only, nonstrict read write and read write strategies, all cluster safe.
  • Ehcache 2.0 is readily distributable with Terracotta Server Array. This gives you cluster safe operation (coherency), HA and scale beyond the limits of an in-process cache, which is how most Hibernate users use Ehcache today. There is the existing ehcache.jar and ehcache-terracotta.jar which provides the client library. (...)

因此,我们鼓励您使用新的实现。配置是通过以下属性完成的:

<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
</property>

它取代了 hibernate.cache.provider_class 属性。

引用文献

关于hibernate - 为什么 EhCacheProvider 被弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3689868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com