⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcachemanager.java

📁 开源项目simpleoa-0.3.zip是最新版本
💻 JAVA
字号:
package com.ejsun.entapps.core.cache;

import java.io.IOException;

import net.sf.ehcache.Cache;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author	Quake Wang
 * @since	2004-5-18
 * @version $Revision: 1.1 $
 * 
 **/
public class DefaultCacheManager implements InitializingBean, CacheManager {
	private static final Log log = LogFactory.getLog(CacheInterceptor.class);
	private net.sf.ehcache.CacheManager ehcacheManager;

	public void afterPropertiesSet() throws Exception {
		ehcacheManager = net.sf.ehcache.CacheManager.create();
	}

	public Cache getCache(String cacheName) {
		if(!ehcacheManager.cacheExists(cacheName)){
			log.warn("Can not find predefined cache: " + cacheName + ", create the default one.");
			try {
				ehcacheManager.addCache(cacheName);
			} catch (Exception e) {
				log.error(e);
				throw new CacheException(e.getMessage());	
			} 
		}
		return ehcacheManager.getCache(cacheName);
	}

	public void flushCaches() {
		for (int i = 0; i < ehcacheManager.getCacheNames().length; i++) {
			String cacheName = ehcacheManager.getCacheNames()[i];
			try {
				ehcacheManager.getCache(cacheName).removeAll();
			} catch (IOException e) {
				log.error("Could not flush cache: " + e, e);
			}
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -