title: Spring Caching not working with Memcached
body: <p>I'm trying to get my web application running with REST API features and caching using Memcached.</p>
  
  <p>Spring does not throw an error while I deploy the application. But the caching does not work. I have used spymemcached Java client along with Spring caching.
  Can someone please tell me where I'm going wrong?
  This is a snippet of my root context</p>
  
  <pre><code>    &lt;cache:annotation-driven /&gt;
  &lt;bean class="net.spy.memcached.MemcachedClient"&gt;
      &lt;constructor-arg ref="serverList" type="java.util.List" /&gt;
  &lt;/bean&gt;
  &lt;context:component-scan base-package="com.restdemo.cache" /&gt;
  
  &lt;util:list id="serverList" value-type="java.net.InetSocketAddress"&gt;
      &lt;bean class="java.net.InetSocketAddress"&gt;
          &lt;constructor-arg value="127.0.0.1" type="java.lang.String" /&gt;
          &lt;constructor-arg value="11211" type="int" /&gt;
      &lt;/bean&gt;
  &lt;/util:list&gt;
  
  &lt;bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"&gt;
      &lt;property name="caches"&gt;
          &lt;set&gt;
              &lt;bean name="coursesCache" class="com.restdemo.cache.Memcache"&gt;
              &lt;/bean&gt;
          &lt;/set&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>This is my implementation of the Cache interface</p>
  
  <pre><code>public class Memcache implements Cache {
  
  @Autowired
  MemcachedClient cache;
  
  private final String name = "";
  
  public void clear() {
      cache.flush();
  
  }
  
  public void evict(Object key) {
      this.cache.delete(key.toString());
  
  }
  
  public ValueWrapper get(Object key) {
      Object value = null;
      try {
          value = cache.get(key.toString());
      } catch (final Exception e) {
          e.printStackTrace();
      }
      if (value == null) {
          return null;
      }
      return new SimpleValueWrapper(value);
  }
  
  public &lt;T&gt; T get(Object arg0, Class&lt;T&gt; arg1) {
      // TODO Auto-generated method stub
      return null;
  }
  
  public &lt;T&gt; T get(Object arg0, Callable&lt;T&gt; arg1) {
      // TODO Auto-generated method stub
      return null;
  }
  
  public String getName() {
      return name;
  }
  
  public Object getNativeCache() {
      return cache;
  }
  
  public void put(Object key, Object value) {
      cache.set(key.toString(), 7 * 24 * 3600, value);
  
  }
  
  public ValueWrapper putIfAbsent(Object arg0, Object arg1) {
      // TODO Auto-generated method stub
      return null;
  }
  }
  </code></pre>
  
  <p>I have used the Cacheable annotation in my RestController as follows-</p>
  
  <pre><code>@GetMapping("/courses")
  @Cacheable("coursesCache")
  public List&lt;Course&gt; getCourses() {
      return courseDAO.getAllCourses();
  }
  </code></pre>
  
  <p>I'm sure that the Memcached client is getting created just fine. Else I was getting the error when the root context beans were created. But then caching isn't working. Any help will be appreciated.</p>