使用ehcache集群休眠高速缓存

使用ehcache集群休眠高速缓存

本文介绍了使用ehcache集群休眠高速缓存:非严格与严格读写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我可能会遇到如此配置的长期缓存集合的问题:

 eternal =falseoverflowToDisk =falsetimeToIdleSeconds =1200
timeToLiveSeconds =1800>
< cacheEventListenerFactory
class =net.sf.ehcache.distribution.RMICacheReplicatorFactory
properties =replicateAsynchronously = true,replicatePuts = true,replicateUpdates = true,replicateUpdatesViaCopy = false,replicateRemovals = true />





 < set name =childrenlazy =falseinverse =true> 
< cache usage =nonstrict-read-write/>
< key column =callout_id/>
< / set>

更新集合时,发生更新的节点和其他节点发生了什么? nonstrict-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.

解决方案

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

这篇关于使用ehcache集群休眠高速缓存:非严格与严格读写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 04:40