I am facing issue while getting value from cache.
java.lang.RuntimeException: java.lang.ClassCastException: com.mycom.admin.domain.User cannot be cast to com.mycom.admin.domain.User
Cache Configuration
@Configuration
@EnableCaching
@AutoConfigureAfter(value = { MetricsConfiguration.class, DatabaseConfiguration.class })
@Profile("!" + Constants.SPRING_PROFILE_FAST)
public class MemcachedCacheConfiguration extends CachingConfigurerSupport {
private final Logger log = LoggerFactory.getLogger(MemcachedCacheConfiguration.class);
@Override
@Bean
public CacheManager cacheManager() {
ExtendedSSMCacheManager cacheManager = new ExtendedSSMCacheManager();
try {
List<SSMCache> list = new ArrayList<>();
list.add(new SSMCache(defaultCache("apiCache"), 86400, false));
cacheManager.setCaches(list);
} catch (Exception e) {
e.printStackTrace();
}
return cacheManager;
}
@Override
public CacheResolver cacheResolver() {
return null;
}
@Override
public CacheErrorHandler errorHandler() {
return null;
}
private Cache defaultCache(String cacheName) throws Exception {
CacheFactory cacheFactory = new CacheFactory();
cacheFactory.setCacheName(cacheName);
cacheFactory.setCacheClientFactory(new MemcacheClientFactoryImpl());
String serverHost = "127.0.0.1:11211";
cacheFactory.setAddressProvider(new DefaultAddressProvider(serverHost));
cacheFactory.setConfiguration(cacheConfiguration());
return cacheFactory.getObject();
}
@Bean
public CacheConfiguration cacheConfiguration() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setConsistentHashing(true);
return cacheConfiguration;
}
}
And annotated with
@Cacheable(value = "apiCache#86400", key = "'User-'.concat(#login)")
I am using com.google.code.simple-spring-memcached 3.5.0
Value is getting cached but while getting application throws class cast error. What would be the possible issues.
class
on your classpath twice? Or do you have it loaded from multiple classloaders (or example in a WebApp environment). The usual cause for a class cannot be cast to itself issues is that the classes are loaded from different places... – Casia