title: How to access Apache camel eh-cache outside camel context?
body: <p>I want to consume data from web service and put it in camel eh-cache.
  later i want to use this cache outside camel context through <strong>CacheManager</strong>.
  I am not finding any way to do it.</p>
  
  <p>In below code I have skipped consumption of web service and used data from Map and provided it to eh-cache but I am not able to access this cache using <strong>CacheManager</strong>.</p>
  
  <p><strong>CamelRouter class</strong></p>
  
  <pre><code>package com.camel;
  
  
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.camel.builder.RouteBuilder;
  import org.apache.camel.component.ehcache.EhcacheConstants;
  import org.apache.camel.main.Main;
  import org.ehcache.Cache;
  import org.ehcache.CacheManager;
  import org.ehcache.config.Configuration;
  import org.ehcache.config.builders.CacheManagerBuilder;
  import org.ehcache.xml.XmlConfiguration;
  
  public class Test {
  
      private static Main main;
  
      public static void main(String[] args) throws Exception {
  
          main = new Main();
          main.addRouteBuilder(new RouteBuilder() {
  
              @Override
              public void configure() throws Exception {
                  from("timer:foo?period=5s&amp;repeatCount=1")
                  .process(exchange -&gt;{
                      Map&lt;String, String&gt; inputMap = new HashMap&lt;&gt;();
                      inputMap.put("name", "murli");
                      inputMap.put("lastname", "hiware");
                      inputMap.put("city", "pune");
                      exchange.getIn().setBody(inputMap);
                      exchange.getIn().setHeader("CamelEhcacheAction", EhcacheConstants.ACTION_PUT_ALL);
                  })
                  .to("ehcache://testCache?configUri=ehcache.xml&amp;keyType=java.lang.String&amp;valueType=java.lang.String")
                  .process(exchange -&gt; {
                      URL myUrl = getClass().getResource("/ehcache.xml"); 
                      Configuration xmlConfig = new XmlConfiguration(myUrl); 
                      CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); 
                      myCacheManager.init();
                      //here I want to access already created testCache component but it is creating new one.
                      Cache&lt;String, String&gt; cache = myCacheManager.getCache("testCache", String.class, String.class);
                      System.out.println("Cache Element:"+cache.get("name"));
                      System.out.println("Exchange Message:"+exchange.getIn().getBody());
  
                  });
              }
          });
  
           main.run();
      }
  
  }
  </code></pre>
  
  <p><strong>ehcache config file</strong></p>
  
  <pre><code>&lt;config
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xmlns='http://www.ehcache.org/v3'
      xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd"&gt;
  
    &lt;cache alias="testCache"&gt; 
      &lt;key-type&gt;java.lang.String&lt;/key-type&gt; 
      &lt;value-type&gt;java.lang.String&lt;/value-type&gt; 
      &lt;resources&gt;
        &lt;heap unit="entries"&gt;2000&lt;/heap&gt; 
        &lt;offheap unit="MB"&gt;100&lt;/offheap&gt; 
      &lt;/resources&gt;
    &lt;/cache&gt;
  
    &lt;cache-template name="myDefaults"&gt; 
      &lt;key-type&gt;java.lang.Long&lt;/key-type&gt;
      &lt;value-type&gt;java.lang.String&lt;/value-type&gt;
      &lt;heap unit="entries"&gt;200&lt;/heap&gt;
    &lt;/cache-template&gt;
  
    &lt;cache alias="bar" uses-template="myDefaults"&gt; 
      &lt;key-type&gt;java.lang.Number&lt;/key-type&gt;
    &lt;/cache&gt;
  
    &lt;cache alias="simpleCache" uses-template="myDefaults" /&gt; 
  
  &lt;/config&gt;
  </code></pre>
  
  <p>please let me know the use case I am trying to achieve is possible with camel eh-cache or not?</p>