Java Code Examples for net.sf.ehcache.CacheManager#create()

The following examples show how to use net.sf.ehcache.CacheManager#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnchachePooFactory.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
@Override
public CachePool createCachePool(String poolName, int cacheSize,
                                 int expiredSeconds) {
    CacheManager cacheManager = CacheManager.create();
    Cache enCache = cacheManager.getCache(poolName);
    if (enCache == null) {

        CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
        cacheConf.setName(poolName);
        if (cacheConf.getMaxEntriesLocalHeap() != 0) {
            cacheConf.setMaxEntriesLocalHeap(cacheSize);
        } else {
            cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
        }
        cacheConf.setTimeToIdleSeconds(expiredSeconds);
        Cache cache = new Cache(cacheConf);
        cacheManager.addCache(cache);
        return new EnchachePool(poolName, cache, cacheSize);
    } else {
        return new EnchachePool(poolName, enCache, cacheSize);
    }
}
 
Example 2
Source File: GenericDaoBase.java    From cosmic with Apache License 2.0 6 votes vote down vote up
@DB()
protected void createCache(final Map<String, ? extends Object> params) {
    final String value = (String) params.get("cache.size");

    if (value != null) {
        final CacheManager cm = CacheManager.create();
        final int maxElements = NumbersUtil.parseInt(value, 0);
        final int live = NumbersUtil.parseInt((String) params.get("cache.time.to.live"), 300);
        final int idle = NumbersUtil.parseInt((String) params.get("cache.time.to.idle"), 300);
        _cache = new Cache(getName(), maxElements, false, live == -1, live == -1 ? Integer.MAX_VALUE : live, idle);
        cm.addCache(_cache);
        s_logger.info("Cache created: " + _cache.toString());
    } else {
        _cache = null;
    }
}
 
Example 3
Source File: EHCacheManagerHolder.java    From steady with Apache License 2.0 6 votes vote down vote up
public static CacheManager getCacheManager(Bus bus, URL configFileURL) {
    CacheManager cacheManager = null;
    if (configFileURL == null) {
        //using the default
        cacheManager = findDefaultCacheManager(bus);
    }
    if (cacheManager == null) {
        if (configFileURL == null) {
            cacheManager = CacheManager.create();
        } else {
            cacheManager = CacheManager.create(configFileURL);
        }
    }
    AtomicInteger a = COUNTS.get(cacheManager.getName());
    if (a == null) {
        COUNTS.putIfAbsent(cacheManager.getName(), new AtomicInteger());
        a = COUNTS.get(cacheManager.getName());
    }
    if (a.incrementAndGet() == 1) {
        //System.out.println("Create!! " + cacheManager.getName());
    }
    return cacheManager;
}
 
Example 4
Source File: CacheFactory.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Subsonic home dir.
    File cacheDir = new File(SettingsService.getSubsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
 
Example 5
Source File: EhcacheApiTest.java    From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/**
 * 使用Ehcache默认配置(classpath下的ehcache.xml)获取单例的CacheManager实例
 */
@Test
public void create01() {
	CacheManager.create();

	String[] cacheNames = CacheManager.getInstance().getCacheNames();
	for (String name : cacheNames) {
		System.out.println("name:" + name);
	}
}
 
Example 6
Source File: DefaultCacheManagerProvider.java    From jerseyoauth2 with MIT License 5 votes vote down vote up
public DefaultCacheManagerProvider()
{
	net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
	config.setUpdateCheck(false);
	CacheConfiguration tokenCacheConfiguration = new CacheConfiguration().
			maxEntriesLocalHeap(DEFAULT_MAX_CACHE_ENTRIES).
			name("tokenCache").
			persistence(new PersistenceConfiguration().strategy(Strategy.NONE));
	tokenCacheConfiguration.validateConfiguration();
	config.addCache(tokenCacheConfiguration );
	cacheManager = CacheManager.create(config);
}
 
Example 7
Source File: CacheFactory.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
public void afterPropertiesSet() {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Airsonic home dir.
    File cacheDir = new File(SettingsService.getAirsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
 
Example 8
Source File: LowFunctionalityDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private LowFunctionality getFromCache(String key) {
	logger.debug("IN");
	String tenantId = this.getTenant();
	LowFunctionality funct = null;
	if (tenantId != null) {
		// The tenant is set, so let's find it into the cache
		String cacheName = tenantId + DEFAULT_CACHE_SUFFIX;
		try {
			if (cacheManager == null) {
				cacheManager = CacheManager.create();
				logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get.");
				logger.debug("OUT");
				return null;
			} else {
				if (!cacheManager.cacheExists(cacheName)) {
					logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get.");
					logger.debug("OUT");
					return null;
				} else {
					Element el = cacheManager.getCache(cacheName).get(key);
					if (el != null) {
						funct = (LowFunctionality) el.getValue();
					}
				}
			}
		} catch (Throwable t) {
			throw new SpagoBIRuntimeException("Error while getting a LowFunctionality cache item with key " + key + " for tenant " + tenantId, t);
		}
	}
	logger.debug("OUT");
	return funct;
}
 
Example 9
Source File: EhCacheManagerFactoryBean.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws IOException, CacheException {
	logger.info("Initializing EhCache CacheManager");
	InputStream is = this.extractEntandoConfig();
	try {
		// A bit convoluted for EhCache 1.x/2.0 compatibility.
		// To be much simpler once we require EhCache 2.1+
		if (this.cacheManagerName != null) {
			if (this.shared && createWithConfiguration == null) {
				// No CacheManager.create(Configuration) method available before EhCache 2.1;
				// can only set CacheManager name after creation.
				this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
				this.cacheManager.setName(this.cacheManagerName);
			} else {
				Configuration configuration = (is != null ? ConfigurationFactory.parseConfiguration(is) :
						ConfigurationFactory.parseConfiguration());
				configuration.setName(this.cacheManagerName);
				if (this.shared) {
					this.cacheManager = (CacheManager) ReflectionUtils.invokeMethod(createWithConfiguration, null, configuration);
				} else {
					this.cacheManager = new CacheManager(configuration);
				}
			}
		} else if (this.shared) {
			// For strict backwards compatibility: use simplest possible constructors...
			this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
		} else {
			this.cacheManager = (is != null ? new CacheManager(is) : new CacheManager());
		}
	} finally {
		if (is != null) {
			is.close();
		}
	}
}
 
Example 10
Source File: EhCache.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public synchronized static final CacheManager getManager() {
	if (manager == null) {
		try {
			System.setProperty(CacheManager.ENABLE_SHUTDOWN_HOOK_PROPERTY, "TRUE");
			URL resource = Cache.class.getResource("/cache.xml");
			manager = CacheManager.create(Paths.get(resource.toURI()).toFile().getAbsolutePath());
		} catch (Throwable e) {
			log.error("Cannot initialize the cache manager");
			return null;
		}
	}
	return manager;
}
 
Example 11
Source File: JbootEhcacheImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootEhcacheImpl() {
    JbootEhCacheConfig config = Jboot.config(JbootEhCacheConfig.class);
    if (StrUtil.isBlank(config.getConfigFileName())) {
        cacheManager = CacheManager.create();
    } else {
        String configPath = config.getConfigFileName();
        if (!configPath.startsWith("/")){
            configPath = PathKit.getRootClassPath()+"/"+configPath;
        }
        cacheManager = CacheManager.create(configPath);
    }
}
 
Example 12
Source File: ApiRateLimitServiceImpl.java    From cosmic with Apache License 2.0 5 votes vote down vote up
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    super.configure(name, params);

    if (_store == null) {
        // get global configured duration and max values
        final String isEnabled = _configDao.getValue(Config.ApiLimitEnabled.key());
        if (isEnabled != null) {
            enabled = Boolean.parseBoolean(isEnabled);
        }
        final String duration = _configDao.getValue(Config.ApiLimitInterval.key());
        if (duration != null) {
            timeToLive = Integer.parseInt(duration);
        }
        final String maxReqs = _configDao.getValue(Config.ApiLimitMax.key());
        if (maxReqs != null) {
            maxAllowed = Integer.parseInt(maxReqs);
        }
        // create limit store
        final EhcacheLimitStore cacheStore = new EhcacheLimitStore();
        int maxElements = 10000;
        final String cachesize = _configDao.getValue(Config.ApiLimitCacheSize.key());
        if (cachesize != null) {
            maxElements = Integer.parseInt(cachesize);
        }
        final CacheManager cm = CacheManager.create();
        final Cache cache = new Cache("api-limit-cache", maxElements, false, false, timeToLive, timeToLive);
        cm.addCache(cache);
        s_logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements);
        cacheStore.setCache(cache);
        _store = cacheStore;
    }

    return true;
}
 
Example 13
Source File: EhcacheBackedMapTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Before
public void prep() {
    this.manager = CacheManager.create();
    this.manager.addCache("cascache");
    this.cache = this.manager.getCache("cascache");
    this.map = new EhcacheBackedMap(this.cache);
}
 
Example 14
Source File: EhcacheHandler.java    From Cynthia with GNU General Public License v2.0 5 votes vote down vote up
/**
  * 缓存实始化
  */
 public void init(){
     
     if(cacheManager == null){
         logger.info("初始化CacheManager");
         
         String localEhcacheXmlName = "ehcache.xml";
         cacheManager = CacheManager.create(this.getClass().getClassLoader().getResource(localEhcacheXmlName));
         if (cacheManager == null) {
         	throw new RuntimeException("无法创建ehcache对象实例,检测ehcache配置文件");
}
     }
 }
 
Example 15
Source File: SakaiCacheManagerFactoryBean.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * This is the init method
 * If using Terracotta, enable caching via sakai.properties and ensure the Terracotta server is reachable
 * Use '-Dcom.tc.tc.config.total.timeout=10000' to specify how long we should try to connect to the TC server
 */
public void afterPropertiesSet() throws IOException {
    log.info("Initializing EhCache CacheManager");
    InputStream is = (this.configLocation != null ? this.configLocation.getInputStream() : null);
    if (this.cacheEnabled == null) {
        this.cacheEnabled = serverConfigurationService.getBoolean("memory.cluster.enabled", false);
    }

    try {
        Configuration configuration = (is != null) ? ConfigurationFactory.parseConfiguration(is) : ConfigurationFactory.parseConfiguration();
        configuration.setName(this.cacheManagerName);
        // force the sizeof calculations to not generate lots of warnings OR degrade server performance
        configuration.getSizeOfPolicyConfiguration().maxDepthExceededBehavior(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT);
        configuration.getSizeOfPolicyConfiguration().maxDepth(100);

        // Setup the Terracotta cluster config
        TerracottaClientConfiguration terracottaConfig = new TerracottaClientConfiguration();

        // use Terracotta server if running and available
        if (this.cacheEnabled) {
            log.info("Attempting to load cluster caching using Terracotta at: "+
                    serverConfigurationService.getString("memory.cluster.server.urls", DEFAULT_CACHE_SERVER_URL)+".");
            // set the URL to the server
            String[] serverUrls = serverConfigurationService.getStrings("memory.cluster.server.urls");
            // create comma-separated string of URLs
            String serverUrlsString = StringUtils.join(serverUrls, ",");
            terracottaConfig.setUrl(serverUrlsString);
            terracottaConfig.setRejoin(true);
            configuration.addTerracottaConfig(terracottaConfig);

            // retrieve the names of all caches that will be managed by Terracotta and create cache configurations for them
            String[] caches = serverConfigurationService.getStrings("memory.cluster.names");
            if (ArrayUtils.isNotEmpty(caches)) {
                for (String cacheName : caches) {
                    CacheConfiguration cacheConfiguration = this.createClusterCacheConfiguration(cacheName);
                    if (cacheConfiguration != null) {
                        configuration.addCache(cacheConfiguration);
                    }
                }
            }

            // create new cache manager with the above configuration
            if (this.shared) {
                this.cacheManager = (CacheManager) ReflectionUtils.invokeMethod(createWithConfiguration, null, configuration);
            } else {
                this.cacheManager = new CacheManager(configuration);
            }
        } else {
            // This block contains the original code from org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java
            // A bit convoluted for EhCache 1.x/2.0 compatibility.
            // To be much simpler once we require EhCache 2.1+
            log.info("Attempting to load default cluster caching.");
            configuration.addTerracottaConfig(terracottaConfig);
            if (this.cacheManagerName != null) {
                if (this.shared && createWithConfiguration == null) {
                    // No CacheManager.create(Configuration) method available before EhCache 2.1;
                    // can only set CacheManager name after creation.
                    this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
                    this.cacheManager.setName(this.cacheManagerName);
                } else {
                    configuration.setName(this.cacheManagerName);
                    if (this.shared) {
                        this.cacheManager = (CacheManager) ReflectionUtils.invokeMethod(createWithConfiguration, null, configuration);
                    } else {
                        this.cacheManager = new CacheManager(configuration);
                    }
                }
            } else if (this.shared) {
                // For strict backwards compatibility: use simplest possible constructors...
                this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
            } else {
                this.cacheManager = (is != null ? new CacheManager(is) : new CacheManager());
            }
        }
    } catch (CacheException ce) {
        // this is thrown if we can't connect to the Terracotta server on initialization
        if (this.cacheEnabled && this.cacheManager == null) {
            log.error("You have cluster caching enabled in sakai.properties, but do not have a Terracotta server running at "+
                    serverConfigurationService.getString("memory.cluster.server.urls", DEFAULT_CACHE_SERVER_URL)+
                    ". Please ensure the server is running and available.", ce);
            // use the default cache instead
            this.cacheEnabled = false;
            afterPropertiesSet();
        } else {
            log.error("An error occurred while creating the cache manager: ", ce);
        }
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example 16
Source File: DomainAccessControlStoreTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupTestSuite() {
    cacheManager = CacheManager.create();
    store = new DomainAccessControlStoreEhCache(cacheManager, new DefaultDomainAccessControlProvisioning());
}
 
Example 17
Source File: SakaiCacheManagerFactoryBean.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * This is the init method
 * If using Terracotta, enable caching via sakai.properties and ensure the Terracotta server is reachable
 * Use '-Dcom.tc.tc.config.total.timeout=10000' to specify how long we should try to connect to the TC server
 */
public void afterPropertiesSet() throws IOException {
    log.info("Initializing EhCache CacheManager");
    InputStream is = (this.configLocation != null ? this.configLocation.getInputStream() : null);
    if (this.cacheEnabled == null) {
        this.cacheEnabled = serverConfigurationService.getBoolean("memory.cluster.enabled", false);
    }

    try {
        Configuration configuration = (is != null) ? ConfigurationFactory.parseConfiguration(is) : ConfigurationFactory.parseConfiguration();
        configuration.setName(this.cacheManagerName);
        // force the sizeof calculations to not generate lots of warnings OR degrade server performance
        configuration.getSizeOfPolicyConfiguration().maxDepthExceededBehavior(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT);
        configuration.getSizeOfPolicyConfiguration().maxDepth(100);

        // Setup the Terracotta cluster config
        TerracottaClientConfiguration terracottaConfig = new TerracottaClientConfiguration();

        // use Terracotta server if running and available
        if (this.cacheEnabled) {
            log.info("Attempting to load cluster caching using Terracotta at: "+
                    serverConfigurationService.getString("memory.cluster.server.urls", DEFAULT_CACHE_SERVER_URL)+".");
            // set the URL to the server
            String[] serverUrls = serverConfigurationService.getStrings("memory.cluster.server.urls");
            // create comma-separated string of URLs
            String serverUrlsString = StringUtils.join(serverUrls, ",");
            terracottaConfig.setUrl(serverUrlsString);
            terracottaConfig.setRejoin(true);
            configuration.addTerracottaConfig(terracottaConfig);

            // retrieve the names of all caches that will be managed by Terracotta and create cache configurations for them
            String[] caches = serverConfigurationService.getStrings("memory.cluster.names");
            if (ArrayUtils.isNotEmpty(caches)) {
                for (String cacheName : caches) {
                    CacheConfiguration cacheConfiguration = this.createClusterCacheConfiguration(cacheName);
                    if (cacheConfiguration != null) {
                        configuration.addCache(cacheConfiguration);
                    }
                }
            }

            // create new cache manager with the above configuration
            if (this.shared) {
                this.cacheManager = (CacheManager) ReflectionUtils.invokeMethod(createWithConfiguration, null, configuration);
            } else {
                this.cacheManager = new CacheManager(configuration);
            }
        } else {
            // This block contains the original code from org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java
            // A bit convoluted for EhCache 1.x/2.0 compatibility.
            // To be much simpler once we require EhCache 2.1+
            log.info("Attempting to load default cluster caching.");
            configuration.addTerracottaConfig(terracottaConfig);
            if (this.cacheManagerName != null) {
                if (this.shared && createWithConfiguration == null) {
                    // No CacheManager.create(Configuration) method available before EhCache 2.1;
                    // can only set CacheManager name after creation.
                    this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
                    this.cacheManager.setName(this.cacheManagerName);
                } else {
                    configuration.setName(this.cacheManagerName);
                    if (this.shared) {
                        this.cacheManager = (CacheManager) ReflectionUtils.invokeMethod(createWithConfiguration, null, configuration);
                    } else {
                        this.cacheManager = new CacheManager(configuration);
                    }
                }
            } else if (this.shared) {
                // For strict backwards compatibility: use simplest possible constructors...
                this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
            } else {
                this.cacheManager = (is != null ? new CacheManager(is) : new CacheManager());
            }
        }
    } catch (CacheException ce) {
        // this is thrown if we can't connect to the Terracotta server on initialization
        if (this.cacheEnabled && this.cacheManager == null) {
            log.error("You have cluster caching enabled in sakai.properties, but do not have a Terracotta server running at "+
                    serverConfigurationService.getString("memory.cluster.server.urls", DEFAULT_CACHE_SERVER_URL)+
                    ". Please ensure the server is running and available.", ce);
            // use the default cache instead
            this.cacheEnabled = false;
            afterPropertiesSet();
        } else {
            log.error("An error occurred while creating the cache manager: ", ce);
        }
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
Example 18
Source File: DefaultCacheProvider.java    From ymate-platform-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public void init(ICaches owner) {
    super.init(owner);
    //
    __cacheManager = CacheManager.create();
}
 
Example 19
Source File: EhcacheTest.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Test
public void basicTest() throws InterruptedException {
    System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");

    Configuration conf = new Configuration();
    conf.setMaxBytesLocalHeap("100M");
    CacheManager cacheManager = CacheManager.create(conf);

    //Create a Cache specifying its configuration.
    Cache testCache = //Create a Cache specifying its configuration.
            new Cache(new CacheConfiguration("test", 0).//
                    memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).//
                    eternal(false).//
                    timeToIdleSeconds(86400).//
                    diskExpiryThreadIntervalSeconds(0).//
                    //maxBytesLocalHeap(1000, MemoryUnit.MEGABYTES).//
                    persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE)));

    cacheManager.addCache(testCache);

    System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");
    byte[] blob = new byte[(1024 * 80 * 1024)];//400M
    Random random = new Random();
    for (int i = 0; i < blob.length; i++) {
        blob[i] = (byte) random.nextInt();
    }

    //        List<String> manyObjects = Lists.newArrayList();
    //        for (int i = 0; i < 10000; i++) {
    //            manyObjects.add(new String("" + i));
    //        }
    //        testCache.put(new Element("0", manyObjects));

    testCache.put(new Element("1", blob));
    System.out.println(testCache.get("1") == null);
    System.out.println(testCache.getSize());
    System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes());
    System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");

    blob = new byte[(1024 * 80 * 1024)];//400M
    for (int i = 0; i < blob.length; i++) {
        blob[i] = (byte) random.nextInt();
    }

    testCache.put(new Element("2", blob));
    System.out.println(testCache.get("1") == null);
    System.out.println(testCache.get("2") == null);
    System.out.println(testCache.getSize());
    System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes());
    System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");

    blob = new byte[(1024 * 80 * 1024)];//400M
    for (int i = 0; i < blob.length; i++) {
        blob[i] = (byte) random.nextInt();
    }
    testCache.put(new Element("3", blob));
    System.out.println(testCache.get("1") == null);
    System.out.println(testCache.get("2") == null);
    System.out.println(testCache.get("3") == null);
    System.out.println(testCache.getSize());
    System.out.println(testCache.getStatistics().getLocalHeapSizeInBytes());
    System.out.println("runtime used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "M");

    cacheManager.shutdown();
}
 
Example 20
Source File: EhCacheConfig.java    From txle with Apache License 2.0 4 votes vote down vote up
@Bean
public CacheManager cacheManager() {
    return CacheManager.create(this.getClass().getResourceAsStream("/ehcache.xml"));
}