/*
 * Copyright 2017 Sixhours.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.sixhours.memcached.cache;

import net.spy.memcached.MemcachedClient;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheAspectSupport;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * {@link EnableAutoConfiguration Auto-configuration} for the Memcached cache.
 * Creates {@link CacheManager} when caching is enabled via {@link EnableCaching}.
 *
 * @author Igor Bolic
 */
@Configuration
@ConditionalOnMissingSpringCacheType
@ConditionalOnClass({MemcachedClient.class, CacheManager.class})
@ConditionalOnBean(CacheAspectSupport.class)
@ConditionalOnMissingBean({CacheManager.class, CacheResolver.class})
@EnableConfigurationProperties(MemcachedCacheProperties.class)
@AutoConfigureBefore(CacheAutoConfiguration.class)
@AutoConfigureAfter(name = "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration")
public class MemcachedCacheAutoConfiguration {

    @Configuration
    @ConditionalOnRefreshScope
    static class RefreshableMemcachedCacheConfiguration {

        private final MemcachedCacheProperties properties;

        RefreshableMemcachedCacheConfiguration(MemcachedCacheProperties properties) {
            this.properties = properties;
        }

        @Bean
        @RefreshScope
        public MemcachedCacheManager cacheManager() throws IOException {
            return new MemcachedCacheManagerFactory(properties).create();
        }
    }

    @Configuration
    @ConditionalOnMissingRefreshScope
    static class MemcachedCacheConfiguration {

        private final MemcachedCacheProperties properties;

        MemcachedCacheConfiguration(MemcachedCacheProperties properties) {
            this.properties = properties;
        }

        @Bean
        public MemcachedCacheManager cacheManager() throws IOException {
            return new MemcachedCacheManagerFactory(properties).create();
        }
    }
}

@@ -1176,24 +1176,96 @@
 issingBean;%0A
+import org.springframework.boot.autoconfigure.condition.SearchStrategy;%0A
 import org.s
@@ -2585,59 +2585,13 @@
     
-private final MemcachedCacheProperties properties;%0A
+@Bean
 %0A   
@@ -2599,174 +2599,125 @@
     
+@
 Refresh
-ableMemcachedCacheConfiguration(MemcachedCacheProperties properties) %7B%0A            this.properties = properties;%0A        %7D%0A%0A        @Bean%0A        @RefreshScope
+Scope%0A        @ConditionalOnMissingBean(value = MemcachedCacheManager.class, search = SearchStrategy.CURRENT)
 %0A   
@@ -2755,32 +2755,67 @@
 er cacheManager(
+MemcachedCacheProperties properties
 ) throws IOExcep
@@ -3029,201 +3029,117 @@
     
-private final MemcachedCacheProperties properties;%0A%0A        MemcachedCacheConfiguration(MemcachedCacheProperties properties) %7B%0A            this.properties = properties;%0A        %7D%0A%0A        @Bean
+@Bean%0A        @ConditionalOnMissingBean(value = MemcachedCacheManager.class, search = SearchStrategy.CURRENT)
 %0A   
@@ -3185,16 +3185,51 @@
 Manager(
+MemcachedCacheProperties properties
 ) throws

Add coniditionl memcached cache bean initialization