title: BootstrapCacheLoader not working with spring boot
body: <p>I am using Spring Boot with EhCache and Jersey, I am having issue to make BootstrapCacheLoader work, debug shows the load function executes and make call to the function (for which I want result to be cached). but once app is started the first request still calls the function and takes it's time to load data and then afterwords it is quick i.e. first call takes around 2 minutes and then following requests take less than a second.</p>
  
  <p>here is my implementation:</p>
  
  <p>ehcache.xml</p>
  
  <pre><code>&lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="ehcache.xsd" 
      updateCheck="true"
      monitoring="autodetect" 
      dynamicConfig="true"&gt;
  
      &lt;diskStore path="java.io.tmpdir" /&gt;
  
      &lt;cache name="idsMap" 
          maxEntriesLocalHeap="1000"
          maxEntriesLocalDisk="10000" 
          eternal="true" 
          diskSpoolBufferSizeMB="20"
          memoryStoreEvictionPolicy="LFU" 
          transactionalMode="off"&gt;
          &lt;persistence strategy="localTempSwap" /&gt;
      &lt;/cache&gt;
  
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>EhCache Config</p>
  
  <pre><code>package com.spinners.rest.config;
  
  import java.util.Map;
  
  import javax.annotation.PostConstruct;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.cache.CacheManager;
  import org.springframework.cache.annotation.EnableCaching;
  import org.springframework.cache.ehcache.EhCacheCacheManager;
  import org.springframework.cache.ehcache.EhCacheFactoryBean;
  import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.io.ClassPathResource;
  
  /**
   * @author sajid
   *
   */
  @Configuration
  @EnableCaching
  public class EhCacheConfig {
  
      @Autowired
      CacheManager cacheManager;
  
      @Bean
      public EhCacheManagerFactoryBean ehCacheManagerFactoryBean() {
          EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
          ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
          return ehCacheManagerFactoryBean;
      }
  
      @Bean
      public CacheManager cacheManager() {
          EhCacheCacheManager cacheManager = new EhCacheCacheManager();
          cacheManager.setCacheManager(ehCacheManagerFactoryBean().getObject());
          return cacheManager;
      }
  
      @Bean
      public MyBootstrapCacheLoaderFactory myBootstrapCacheLoaderFactory() {
          return new MyBootstrapCacheLoaderFactory();
      }
  
      @Bean
      public EhCacheFactoryBean ehCacheFactory() {
          EhCacheFactoryBean ehCacheFactory = new EhCacheFactoryBean();
          ehCacheFactory.setCacheManager(ehCacheManagerFactoryBean().getObject());
          ehCacheFactory.setBootstrapCacheLoader(myBootstrapCacheLoaderFactory());
          return ehCacheFactory;
      }
  
  }
  </code></pre>
  
  <p>Here is my implementation of BootstrapCacheLoader</p>
  
  <pre><code>package com.spinners.rest.config;
  
  import java.util.List;
  import java.util.Map;
  import java.util.Properties;
  
  import javax.annotation.PostConstruct;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  import com.spinners.rest.repositories.IdsMapRepository;
  import net.sf.ehcache.CacheException;
  import net.sf.ehcache.Ehcache;
  import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
  import net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory;
  
  public class MyBootstrapCacheLoaderFactory extends BootstrapCacheLoaderFactory implements BootstrapCacheLoader {
  
      @Autowired
      private IdsMapRepository idsMapRepo;
  
      public MyBootstrapCacheLoaderFactory() {
          super();
      }
  
      @Override
      public BootstrapCacheLoader createBootstrapCacheLoader(Properties properties) {
          return new MyBootstrapCacheLoaderFactory();
      }
  
      public Object clone() throws CloneNotSupportedException {
          return super.clone();
      }
  
      public boolean isAsynchronous() {
          return false;
      }
  
      public void load(Ehcache ehCache) throws CacheException {   
  
          try {
              // function for which I want to load data in cache
              Map&lt;String, String&gt; idsMap = idsMapRepo.getIdsMap();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>any suggestions? thanks in advance friends.</p>
  
  <p>Best Regards
  Sajid</p>