Search code examples
ehcacheehcache-3

Does ehcache 3.8.1 still use ehcache.xml for configuration?


Does ehcache 3.8.1 no longer automatically pick up the configuration settings in an ehcache.xml file at the source root directory?


Solution

  • Yes, it's looks so, now it needs to be done using a XML file by configuringe a CacheManager at creation time, according to this schema definition.

    XML programmatic parsing

    If you are obtaining your CacheManager through the JSR-107 API, what follows is done automatically when invoking javax.cache.spi.CachingProvider.getCacheManager(java.net.URI, java.lang.ClassLoader)

    final URL myUrl = getClass().getResource("/configs/docs/getting-started.xml"); 
    XmlConfiguration xmlConfig = new XmlConfiguration(myUrl); 
    CacheManager myCacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); 
    myCacheManager.init();  
    
    1. Obtain a URL to your XML file’s location
    2. Instantiate an XmlConfiguration passing the XML file’s URL to it
    3. Using the static
    org.ehcache.config.builders.CacheManagerBuilder.newCacheManager(org.ehcache.config.Configuration)
    

    allows you to create your CacheManager instance using the Configuration from the XmlConfiguration

    1. Initialize the cacheManager before it is used.

    Reference - http://www.ehcache.org/documentation/3.8/xml.html