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

📄 s3oehcachefactory.java

📁 单点登陆
💻 JAVA
字号:
package net.s3o.core.cache;

import java.util.Iterator;
import java.util.List;

import net.s3o.common.S3OLog;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;

public class S3OEhCacheFactory implements InitializingBean, DisposableBean {

	private Resource configLocation;

	private boolean shared = false;

	private CacheManager cacheManager;
	
	private List cacheList=null;
	
	
	public Cache getCacheByName(String name){
		return cacheManager.getCache(name);
	}
	
	public void afterPropertiesSet() throws Exception {

		if (this.shared) {
			// Shared CacheManager singleton at the VM level.
			if (this.configLocation != null) {
				this.cacheManager = CacheManager.create(this.configLocation
						.getInputStream());
			} else {
				this.cacheManager = CacheManager.create();
			}
		} else {
			// Independent CacheManager instance (the default).
			if (this.configLocation != null) {
				this.cacheManager = new CacheManager(this.configLocation
						.getInputStream());
			} else {
				this.cacheManager = new CacheManager();
			}
		}
		
		if (cacheList!=null){
			for (Iterator cacheNameI=cacheList.iterator();cacheNameI.hasNext();){
				String cacheName=(String)cacheNameI.next();
				if (!this.cacheManager.cacheExists(cacheName)) {
					this.cacheManager.addCache(cacheName);
					S3OLog.dealMessage(cacheName," 该cache不存在,使用默认设置创建");
				}else{
					
				}
			}
		}
	}
	
	public void setConfigLocation(Resource configLocation) {
		this.configLocation = configLocation;
	}

	public void setShared(boolean shared) {
		this.shared = shared;
	}
	

	public void destroy() {

		this.cacheManager.shutdown();
	}

	public List getCacheList() {
		return cacheList;
	}

	public void setCacheList(List cacheList) {
		this.cacheList = cacheList;
	}

}

⌨️ 快捷键说明

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