springboot:memcached

阅读更多
pom.xml
==========================================

       
            com.google.code.simple-spring-memcached
            spymemcached
            2.8.4
       

==========================================
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;
    }

//    //    destroy-method="shutdown">
//       
//         
//       

//       
//           
//             
//           

//       

//   

    @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;
    }
}

你可能感兴趣的:(springboot,memcached)