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 分钟陈旧版本?
请注意超时和异步复制。
最佳答案
读写:如果两个事务试图修改数据,那么这些事务在“已提交读”级别(或可重复读,如果数据库设置为可重复读)被隔离——通常这就足够了,通常我们不需要“可序列化”隔离级别。
非严格读写:缓 stub 本没有锁定,所以如果两个事务修改数据我们永远不知道我们得到了什么,我们无法保证缓存状态 = 数据库状态。
只有当数据不太可能被两个事务同时修改时,这才是安全的。我们也需要设置适当的缓存超时。
有关更多详细信息和非常好的解释,请查看此处:hibernate cache strategy
关于java - 带 ehcache : nonstrict vs. 严格读写的集群 hibernate 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5079615/