title: Spring Cache: Using memcached as a distributed cache
body: <p>For a number of java services we're using AWS ElastiCache as a distributed cache integrated by Spring Cache abstraction and spymemcached.</p>
  
  <p>In one service I see the behaviour that i get a diffent type of result than I expect, leading to a ClassCastException. To be precise: I have a cache key and as a result I expect a List, but instead i get a result of Type2.</p>
  
  <p>We have defined a number of caches, some of the use the same cache key:</p>
  
  <pre><code>Cache1:
  cacheKey -&gt; List&lt;Type1&gt;
  
  Cache2:
  cacheKey -&gt; Type2
  </code></pre>
  
  <p>Since they are in different caches, this works when we use a simple hashmap based cache. With ElastiCache/Memcached however it seems we don't really have different caches (which would make sense from what I know of memcached - which is not much).</p>
  
  <p>I would have expected spymemcached to take care of this by manipulating cache keys so the application wouldnt need to be aware of the actual cache implementation (This could be done by manipulating cache keys and prefixing them with the cache name i.e.).</p>
  
  <p>From a few debugging sessions and the errors that I see, this doesn't seem to be the case.</p>
  
  <p>I've specifically looked at this class:</p>
  
  <p>com.google.code.ssm.spring.SSMCache</p>
  
  <pre><code>L82:  value = cache.get(getKey(key), null);
  L154: private String getKey(final Object key) {
  L155:    return key.toString();
  L156: }
  </code></pre>
  
  <p>I would have expected to have the getKey() method to prefix with a cache name.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Do I understand correctly what is going on here?</li>
  <li>Is there maybe something that can be configured with spymemcached to make it behave in the expected way?</li>
  </ol>
  
  <p>Also, any other thoughts are appriciated! Thanks!</p>