문제

How to use simple-spring-memcached library (SSM) with AWS Elasti Cache Auto Discovery feature? We are using spymemcached as client.

도움이 되었습니까?

해결책

So currently you are using spymemcached and want to add cache layer using simple spring memcached (SSM), right? If yes then please provide your current configuration for spymemcached. It should be easy to use the same configuration with SSM.

UPDATE

I've added new dedicated memcached provider in SSM that uses AWS ElastiCache Cluster Client. It is available on master branch and not released yet. If you build SSM from master or use snapshot available in this repository then you can use Auto Discovery feature.

Remove dependencies to spymemcached-provider and spymemcached instead add a new dependency:

<dependency>
  <groupId>com.google.code.simple-spring-memcached</groupId>
  <artifactId>aws-elasticache-provider</artifactId>
  <version>3.4.1-SNAPSHOT</version>
</dependency>

Use below configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context" xmlns:cache="http://www.springframework.org/schema/cache"
        xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.1.xsd
           http://www.springframework.org/schema/cache 
           http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">

  <cache:annotation-driven />

  <bean name="cacheManager" class="com.google.code.ssm.spring.SSMCacheManager">
    <property name="caches">
      <set>
        <bean class="com.google.code.ssm.spring.SSMCache">
          <constructor-arg name="cache" index="0" ref="defaultCache" />
          <!-- 5 minutes -->
          <constructor-arg name="expiration" index="1" value="300" />
          <!-- @CacheEvict(..., "allEntries" = true) won't work because allowClear is false, 
           so we won't flush accidentally all entries from memcached instance -->
          <constructor-arg name="allowClear" index="2" value="false" />
        </bean>
      </set>
    </property>
  </bean>

  <bean name="defaultCache" class="com.google.code.ssm.CacheFactory">
    <property name="cacheName" value="defaultCache" />
    <property name="cacheClientFactory">
      <bean name="cacheClientFactory" class="com.google.code.ssm.providers.elasticache.MemcacheClientFactoryImpl" />
    </property>
    <property name="addressProvider">
      <bean class="com.google.code.ssm.config.DefaultAddressProvider">
      <!-- set only single address to configuration endpoint -->    
        <property name="address" value="mycluster.fnjyzo.cfg.use1.cache.amazonaws.com:11211" />
      </bean>
    </property>
    <property name="configuration">
      <bean class="com.google.code.ssm.providers.elasticache.ElastiCacheConfiguration">
        <!-- set client mode to dynamic to enable Auto Discovery feature -->
        <property name="clientMode" value="#{T(net.spy.memcached.ClientMode).Dynamic}" />
      </bean>
    </property>
  </bean>
</beans>

And let me know if it works for you.

UPDATE 2

New Simple Spring Memcached version 3.5.0 with AWS Auto Discovery feature is available on github and central maven repository.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top