1

AWS Elasti Cache Auto Discovery 機能で simple-spring-memcached ライブラリ (SSM) を使用する方法を教えてください。spymemcached をクライアントとして使用しています。

4

1 に答える 1

0

現在、あなたは spymemcached を使用しており、Simple Spring memcached (SSM) を使用してキャッシュ レイヤーを追加したいと考えていますよね? はいの場合、spymemcached の現在の構成を提供してください。SSM で同じ構成を使用するのは簡単なはずです。

アップデート

AWS ElastiCache Cluster Client を使用する新しい専用 memcached プロバイダーを SSM に追加しました。master ブランチで利用可能で、まだリリースされていません。マスターから SSM を構築するか、このリポジトリで利用可能なスナップショットを使用する場合、自動検出機能を使用できます。

spymemcached-providerspymemcachedへの依存関係を削除し、代わりに新しい依存関係を追加します。

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

以下の構成を使用します。

<?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>

それがあなたのために働くかどうか私に知らせてください。

更新 2

AWS Auto Discovery 機能を備えた新しい Simple Spring Memcached バージョン3.5.0は、github および中央の Maven リポジトリで利用できます。

于 2014-04-01T07:50:15.590 に答える