2014-01-24 126 views

回答

2

找到解决方案 - 配置与memcached配置相同。

  1. 添加以下的的pom.xml

<dependency> 
     <groupId>com.google.code.simple-spring-memcached</groupId> 
     <artifactId>spring-cache</artifactId> 
     <version>3.3.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.code.simple-spring-memcached</groupId> 
     <artifactId>xmemcached-provider</artifactId> 
     <version>3.3.0</version> 
    </dependency> 

  1. 添加按照调度-servlet.xml中

<bean name="memcacheManager" 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"/> 
       <!-- 3 days --> 
       <constructor-arg name="expiration" index="1" value="259200"/> 
       <!-- @CacheEvict(..., "allEntries" = true) doesn't work --> 
       <constructor-arg name="allowClear" index="2" value="true"/> 
      </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.xmemcached.MemcacheClientFactoryImpl"/> 
    </property> 
    <property name="addressProvider"> 
     <bean class="com.google.code.ssm.config.DefaultAddressProvider"> 
      <property name="address" value="xxx.yyy.cache.amazonaws.com:11211"/> 
     </bean> 
    </property> 
    <property name="configuration"> 
     <bean class="com.google.code.ssm.providers.CacheConfiguration"> 
      <property name="consistentHashing" value="true"/> 
     </bean> 
    </property> 
</bean> 

命名空间如下:

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