2

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

Victory
  • 5,811
  • 2
  • 26
  • 45
Poorna Subhash
  • 2,078
  • 2
  • 21
  • 28

1 Answers1

1

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.

ragnor
  • 2,498
  • 1
  • 22
  • 25
  • No. I have already integrated my spring-cache layer with SSM. My Cache Server is Amazon ElastiCache. When using SSM with spymemcache, we have to give urls of all cache nodes as address property. When nodes are added/removed requires configuration change in app and a restart. To avoid this Amazon has Auto-discovery feature wherein you provide only address of cache cluster and it'll auto discover all remaining nodes. Please refer links http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html#AutoDiscovery.ClusterClient (has link to Java client) – Poorna Subhash Apr 02 '14 at 12:40
  • I see two ways how you can use Auto-discovery in SSM. Firs one is to implement com.google.code.ssm.config.AddressProvider to get list of available memcached instances and optionaly implement also com.google.code.ssm.config.AddressChangeListener to listen on servers changes. Second is to create dedicated provider for SSM. Because this client is a fork of spymemcached it should be simple to just extend existing spymemcached-provider to add support of auto-discovery setting. – ragnor Apr 03 '14 at 05:28
  • Thanks for quickly putting this across. I'll try it sometime next week and will let you know. – Poorna Subhash Apr 11 '14 at 08:51
  • I have verified this both on my local cache server (with ClientMode.Static) and on AWS elasti-cache server (with ClientMode.Dynamic). It's all working fine. – Poorna Subhash Apr 22 '14 at 11:05
  • when are you planning to release this? – Poorna Subhash Jun 12 '14 at 11:57
  • I think that I'll release it in a few days. – ragnor Jun 12 '14 at 12:10