我用两台机子(tomcat1和tomcat2)做了负载均衡,用的是ehcache,做了usercache 和resourcecache,问题出现了,在tomcat1上注册的用户无法在tomcat2上登录,后来我修改了acegi的设置,让用户登录时不从usercache读取数据,而是从数据库获取数据,但是随之问题又出现了,在tomcat1上注册的用户,可以在tomcat2上登陆了,但是权限却无法同步了。于是我明白了,一定要用ehcache的分步式缓存,其实ecache自1.2+版本后就支持了分步式缓存,配置也很简单,以下是我的配置例子,希望对你们有用
<defaultCache
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"/>
<!--<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,multicastGroupPort=4446, timeToLive=32"/>-->
<!--这是在配置tomcat1服务器,其中192.168.0.2是tomcat1的IP,192.168.0.118是tomcat2的IP,tomcat2的配置就是把这些IP互换就行了-->
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,rmiUrls=//192.168.0.118:40001/userCache|//192.168.0.118:40001/resourceCache"/>
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties="hostName=192.168.0.2,port=40001,socketTimeoutMillis=120000"/>
<!-- acegi cache-->
<cache name="userCache" maxElementsInMemory="10000" eternal="true" overflowToDisk="true">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
</cache>
<!-- acegi cache-->
<cache name="resourceCache" maxElementsInMemory="10000" eternal="true" overflowToDisk="true">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
</cache>
注意:如果你用的是tomcat服务器,请一定要将ehcache的jar包放到tomcat的common/lib下,否则会出现
java.io.EOFException
希望这些能对你们有用
分享到:
相关推荐
hibernate ehcache.xml 配置详解
ehcache配置使用详解,里面有具体的例子
(见下图,为了减少get这几条网络传输,我们会在每个应用服务器上增加本地的ehcache缓存作为二级缓存,即第一次get到的数据存入ehcache,后面output输出即可从本地ehcache中获取,不用再访问redis了,所以就减少了...
ehcache配置文件里面有大量注解方便解读和理解湖北卫视 2018-10-26 2018-10-26 黄鹤楼酒违法 一般违法 50
EHCache配置
里面有jar,ssm框架,以及ehcache的配置,照着改成自己的就可以,注意不要用实体类传入参数,不懂的看我博客
ehcache缓存配置详解 个人通过查资料和实践后总结
Ehcache缓存配置说明帮助你如何使用Ehcache
Ehcache配置及说明.docx
NULL 博文链接:https://jlwangjinshuang-163-com.iteye.com/blog/1058617
EHCAHCE基于JGROUP的集群配置方案,内含相关配置文件,及配置说明
Ehcache缓存配置
SpringMVC+Mybatis+Spring+Shiro+ehcache整合配置文件
介绍了ehcache缓存的基本原理和配置说明
NULL 博文链接:https://lvsenlin.iteye.com/blog/975570
将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名。 , monitorPor t=9889" /> 3.在\ehcache-monitor-kit-1.0.0\etc\ehcache-monitor.conf中可以配置监控的ip和端口号。 4....
ehcache缓存的jar包和配置文件。
ehcache 监控安装配置过程的详细记录。
java ehcache terracotta 集群, 分布式缓存配置