使用 ehcache 的集群 Hibernate 缓存:非严格与严格读写
nonstrict-read-write
和 read-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-write
和read-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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
读写:如果两个事务尝试修改数据,那么这些事务在“已提交读”级别(或可重复读,如果数据库设置为该级别)被隔离 - 通常这就足够了,通常我们不需要“可序列化”隔离级别。
非严格读写:缓存根本没有锁定,因此如果两个事务修改数据,我们永远不知道我们得到了什么,我们无法保证缓存状态 = 数据库状态。
仅当数据不太可能被两个事务同时修改时,这才是安全的。我们还需要设置适当的缓存超时。
有关更多详细信息和非常好的解释,请参见此处: 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