@SuppressWarnings("unchecked") public void init() { log.info("Loading ehcache"); // log.debug("Appcontext: " + applicationContext.toString()); try { // instance the manager CacheManager cm = CacheManager.getInstance(); // Use the Configuration to create our caches Configuration configuration = new Configuration(); // set initial default cache name String defaultCacheName = Cache.DEFAULT_CACHE_NAME; // add the configs to a configuration for (CacheConfiguration conf : configs) { // set disk expiry conf.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds); // set eviction policy conf.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy); if (null == cache) { // get first cache name and use as default defaultCacheName = conf.getName(); configuration.addDefaultCache(conf); } else { configuration.addCache(conf); } } // instance the helper ConfigurationHelper helper = new ConfigurationHelper(cm, configuration); // create the default cache cache = helper.createDefaultCache(); // init the default cache.initialise(); cache.bootstrap(); // create the un-init'd caches Set<Cache> caches = helper.createCaches(); if (log.isDebugEnabled()) { log.debug( "Number of caches: " + caches.size() + " Default cache: " + (cache != null ? 1 : 0)); } for (Cache nonDefaultCache : caches) { nonDefaultCache.initialise(); nonDefaultCache.bootstrap(); // set first cache to be main local member if (null == nonDefaultCache) { log.debug("Default cache name: {}", defaultCacheName); nonDefaultCache = cm.getCache(defaultCacheName); } } } catch (Exception e) { log.warn("Error on cache init", e); } if (log.isDebugEnabled()) { log.debug("Cache is null? {}", (null == cache)); } }