==========================================
==========================================
application.properties
==========================================
cache.timeout=2000
cache.url=172.16.30.58:11211
==========================================
MemcachedConfigation.java
==========================================
@Configuration
public class MemcachedConfigation {
//
//
//
//
//
@Bean("spy-memcached-conf")
public ConnectionFactoryBuilder connectionFactoryBuilder(@Value("${cache.timeout}")int timeout){
ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder();
connectionFactoryBuilder.setProtocol(ConnectionFactoryBuilder.Protocol.BINARY);
connectionFactoryBuilder.setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT);
connectionFactoryBuilder.setOpTimeout(timeout);
return connectionFactoryBuilder;
}
//
//
//
//
//
//
//
//
//
//
@Bean(name = "memcachedClient", destroyMethod = "shutdown")
public MemcachedClient memcachedClient(@Qualifier("spy-memcached-conf") ConnectionFactoryBuilder builder,
@Value("${cache.url}")String url) throws IOException {
MemcachedClient memcachedClient = new MemcachedClient(builder.build(), AddrUtil.getAddresses(url));
return memcachedClient;
}
}