문제

For a number of java services we're using AWS ElastiCache as a distributed cache integrated by Spring Cache abstraction and spymemcached.

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.

We have defined a number of caches, some of the use the same cache key:

Cache1:
cacheKey -> List<Type1>

Cache2:
cacheKey -> Type2

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).

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.).

From a few debugging sessions and the errors that I see, this doesn't seem to be the case.

I've specifically looked at this class:

com.google.code.ssm.spring.SSMCache

L82:  value = cache.get(getKey(key), null);
L154: private String getKey(final Object key) {
L155:    return key.toString();
L156: }

I would have expected to have the getKey() method to prefix with a cache name.

So my questions are:

  1. Do I understand correctly what is going on here?
  2. Is there maybe something that can be configured with spymemcached to make it behave in the expected way?

Also, any other thoughts are appriciated! Thanks!

도움이 되었습니까?

해결책

Ok, i found this is an issue with version 3.2.0 of simple-spring-memcached. Version 3.3.0 fixes it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top