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

The following examples show how to use net.sf.ehcache.CacheManager#getCacheNames() . 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: EhCacheManagerFactoryBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
       super.afterPropertiesSet();
	//Now look for any custom configuration.
   	CacheManager cm = (CacheManager) this.getObject();
   	if (cm != null) {
   		String cacheNames[]= cm.getCacheNames();

   		//Check for old configuration properties.
   		for (String cacheName:cacheNames) {
   			if(serverConfigurationService.getString(cacheName) == null) {
   				log.warn("Old cache configuration "+ cacheName+ " must be changed to memory."+ cacheName);
   			}
   			String config = serverConfigurationService.getString("memory."+ cacheName);
   			if (config != null && config.length() > 0) {
   				log.info("Found configuration override for cache: "+ cacheName+ " of: "+ config);
   				Cache cache = cm.getCache(cacheName);
   				if (cache != null) {
   					new CacheInitializer().configure(config).initialize(cache.getCacheConfiguration());
   				}
   			}
   		}
   	}
   }
 
Example 2
Source File: EhCacheManagerFactoryBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
       super.afterPropertiesSet();
	//Now look for any custom configuration.
   	CacheManager cm = (CacheManager) this.getObject();
   	if (cm != null) {
   		String cacheNames[]= cm.getCacheNames();

   		//Check for old configuration properties.
   		for (String cacheName:cacheNames) {
   			if(serverConfigurationService.getString(cacheName) == null) {
   				log.warn("Old cache configuration "+ cacheName+ " must be changed to memory."+ cacheName);
   			}
   			String config = serverConfigurationService.getString("memory."+ cacheName);
   			if (config != null && config.length() > 0) {
   				log.info("Found configuration override for cache: "+ cacheName+ " of: "+ config);
   				Cache cache = cm.getCache(cacheName);
   				if (cache != null) {
   					new CacheInitializer().configure(config).initialize(cache.getCacheConfiguration());
   				}
   			}
   		}
   	}
   }
 
Example 3
Source File: CacheInformationProvider.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();

    for (CacheManager cacheManager : CacheManager.ALL_CACHE_MANAGERS) {
        LinkedHashMap<String, Object> jsonForManager = new LinkedHashMap<>();
        json.put(cacheManager.getName(), jsonForManager);

        for (String cacheName : cacheManager.getCacheNames()) {
            Cache cache = cacheManager.getCache(cacheName);
            LinkedHashMap<String, Object> cacheJson = new LinkedHashMap<>();
            jsonForManager.put(cacheName, cacheJson);

            cacheJson.put("Cache configuration information", getCacheConfigurationInformationAsJson(cache));
            cacheJson.put("Cache runtime information", getCacheRuntimeInformationAsJson(cache));
        }
    }

    return json;
}
 
Example 4
Source File: ECacheProvider.java    From anyline with Apache License 2.0 5 votes vote down vote up
public List<String> getCacheNames(){
	List<String> names = new ArrayList<String>();
	CacheManager manager = createManager();
	for(String name:manager.getCacheNames()){
		names.add(name);
	}
	return names;
}
 
Example 5
Source File: ECacheProvider.java    From anyline with Apache License 2.0 5 votes vote down vote up
public List<Cache> getCaches(){
	List<Cache> caches = new ArrayList<Cache>();
	CacheManager manager = createManager();
	for(String name:manager.getCacheNames()){
		caches.add(manager.getCache(name));
	}
	return caches;
}
 
Example 6
Source File: CacheUtil.java    From ml-blog with MIT License 5 votes vote down vote up
public static void deleteAll() {
    CacheManager cacheManager = SpringContext.getBeanByType(CacheManager.class);
    String[] cacheNames = cacheManager.getCacheNames();
    for (String cacheName : cacheNames) {
        Cache cache = cacheManager.getCache(cacheName);
        cache.removeAll();
        cache.flush();
    }
}
 
Example 7
Source File: EhcacheApiTest.java    From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/**
 * 基于classpath下的配置文件创建CacheManager实例
 */
@Test
public void create04() {
	URL url = getClass().getResource("/cache/ehcache.xml");
	CacheManager manager = CacheManager.newInstance(url);
	String[] cacheNames = manager.getCacheNames();

	for (String name : cacheNames) {
		System.out.println("[ehcache.xml]name:" + name);
	}
}
 
Example 8
Source File: EhcacheApiTest.java    From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/**
 * 基于IO流得到配置文件,并创建CacheManager实例
 */
@Test
public void create05() throws Exception {
	InputStream fis = new FileInputStream(new File("src/test/resources/ehcache/ehcache.xml").getAbsolutePath());
	CacheManager manager = CacheManager.newInstance(fis);
	fis.close();
	String[] cacheNames = manager.getCacheNames();

	for (String name : cacheNames) {
		System.out.println("[ehcache.xml]name:" + name);
	}
}
 
Example 9
Source File: EhcacheTest.java    From blog with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void main(String[] args) {
	try {

		// 创建一个CacheManager实例
		CacheManager manager = new CacheManager();
		// 增加一个cache
		manager.addCache("cardCache");
		// 获取所有cache名称
		String[] cacheNamesForManager = manager.getCacheNames();
		int iLen = cacheNamesForManager.length;
		System.out.println("缓存名称列表:----------------------------");
		for (int i = 0; i < iLen; i++) {
			System.out.println(cacheNamesForManager[i].toString());
		}

		// 获取cache对象
		Cache cache = manager.getCache("cardCache");
		// create
		Element element = new Element("username", "howsky");
		cache.put(element);

		// get
		Element element_get = cache.get("username");
		Object value = element_get.getObjectValue();
		System.out.println(value.toString());
		
		Element element_get2 = cache.get("username");
		System.out.println(element_get2==element_get);

		// update
		cache.put(new Element("username", "howsky.net"));
		// get
		Element element_new = cache.get("username");
		
		System.out.println(element_new==element_get);
		
		Object value_new = element_new.getObjectValue();
		System.out.println(value_new.toString());

		cache.remove("username");

		// 移除cache
		manager.removeCache("cardCache");

		// 关闭CacheManager
		manager.shutdown();

	} catch (Exception e) {

		System.out.println(e.getMessage());

	}
}