使用 ehcache 的集群 Hibernate 缓存:非严格与严格读写

发布于 2024-10-18 11:53:01 字数 1016 浏览 12 评论 0原文

nonstrict-read-writeread-write 之间的真正区别是什么?我可以阅读 ehcache 和 Hibernate 文档,但据我所知,他们只说“如果进行更新,读写会更好”。我觉得不太令人满意。

我可能对长期缓存集合配置有问题,如下所示:

<cache name="trx.domain.Parent.children" maxElementsInMemory="5000"
    eternal="false" overflowToDisk="false" timeToIdleSeconds="1200"
    timeToLiveSeconds="1800">
    <cacheEventListenerFactory
        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
        properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true" />

<set name="children" lazy="false" inverse="true">
    <cache usage="nonstrict-read-write"/>
    <key column="callout_id" />
    <one-to-many class="Child" />
</set>

当集合更新时,在发生更新的节点和其他节点上到底会发生什么?这里的nonstrict-read-writeread-write有什么区别?节点是否有可能使用缓存中 10 分钟后的旧版本?

请注意长时间的超时和异步复制。

What is the real difference between nonstrict-read-write and read-write? I can read ehcache and Hibernate docs, but as far as I can see they only say that "read-write is better if you do updates". I find it unsatisfactory.

I may have an issue with long-lived cached collection configured like this:

<cache name="trx.domain.Parent.children" maxElementsInMemory="5000"
    eternal="false" overflowToDisk="false" timeToIdleSeconds="1200"
    timeToLiveSeconds="1800">
    <cacheEventListenerFactory
        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
        properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true" />

<set name="children" lazy="false" inverse="true">
    <cache usage="nonstrict-read-write"/>
    <key column="callout_id" />
    <one-to-many class="Child" />
</set>

What exactly happens when the collection is updated, on the node where the update occurs and others? What is the difference between nonstrict-read-write and read-write here? Is it possible that a node will use its stale 10-minute version from cache?

Note the lengthy timeouts and asynchronous replication.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2024-10-25 11:53:01

读写:如果两个事务尝试修改数据,那么这些事务在“已提交读”级别(或可重复读,如果数据库设置为该级别)被隔离 - 通常这就足够了,通常我们不需要“可序列化”隔离级别。

非严格读写:缓存根本没有锁定,因此如果两个事务修改数据,我们永远不知道我们得到了什么,我们无法保证缓存状态 = 数据库状态。

仅当数据不太可能被两个事务同时修改时,这才是安全的。我们还需要设置适当的缓存超时。

有关更多详细信息和非常好的解释,请参见此处: hibernate 缓存策略

Read-write: if two transactions tries to modify data, then these transactions are isolated at the "read committed" level (or repeatable read, if database is set to that) - usually that's enough, typically we don't need "serializable" isolation level.

Nonstrict read-write: cache is not locked at all, so if two transactions modify data we never know what we get, we don't have guarantee that cache state = database state.

This is safe only if it is very unlikely that data would be modified simultaneously by two transactions. We need to set appropriate cache timeout too.

For more details and a very good explanation look here: hibernate cache strategy

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文