在我的Spring应用程序中,我使用以下cache(ehcache
):
<bean id="statelessTicketCache"
class="org.springframework.security.cas.authentication.EhCacheBasedTicketCache">
<property name="cache">
<bean id="ehcache" class="net.sf.ehcache.Cache" init-method="initialise"
destroy-method="dispose">
<constructor-arg value="casTickets" />
<constructor-arg value="0" />
<constructor-arg value="true" />
<constructor-arg value="false" />
<constructor-arg value="3600" />
<constructor-arg value="900" />
<property name="cacheManager" ref="cacheManager" />
</bean>
</property>
</bean>
在此缓存中,我将访问票证存储到我的 API 后端。一切都与单节点Tomcat8完美配合。但是,当我尝试在具有负载均衡器 (ELB) 和 N Tomcats(在 EC2 实例上)的 AWS 集群中使用 2 个或更多实例时,我遇到了每个节点都使用自己的 statelessTicketCache
实例运行的问题。
我需要在我的集群中复制此ehcache statelessTicketCache
。可能吗?如果是这样,您能否为此提供一个示例配置?
更新
我想,我将退出Ehcache
解决方案,并尝试使用 Redis
(AWS Elastic cache
在 Redis 引擎上)配置statelessTicketCache
,并使用以下 Spring CAS 的实现 https://github.com/vnomics/spring-stateless-ticket-cache-redis 无状态票证缓存 Redis
我已经从Ehcache解决方案中移出,并使用Redis(Redis 引擎上的AWS弹性缓存)配置了statelessTicketCache
,并具有Spring CAS无状态票证缓存Redis的以下实现 https://github.com/vnomics/spring-stateless-ticket-cache-redis。
现在,一切正常。