📄 ehcachefunctinobyname.java
字号:
package org.artemis.manager.auth.cache.info;
import java.io.Serializable;
import org.apache.log4j.Logger;
import org.springframework.dao.DataRetrievalFailureException;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Element;
import org.artemis.right.model.Function;
public class EhCacheFunctinoByName implements FunctionByNameCache {
private static Logger logger=Logger.getLogger(EhCacheFunctinoByName.class);
private Cache cache;
public void setCache(Cache cache) {
this.cache = cache;
}
public Cache getCache() {
return cache;
}
/**
* 从缓存中获得Function
*/
public Function getFunctionByCache(String functionname) {
Element element = null;
try {
element = cache.get(functionname);
} catch (CacheException cacheException) {
throw new DataRetrievalFailureException("Cache failure: "
+ cacheException.getMessage());
}
/*
if (logger.isDebugEnabled()) {
logger.debug("Cache hit: " + (element != null) + "; functionname: "
+ functionname);
}
*/
if (element == null) {
return null;
} else {
return (Function) element.getValue();
}
}
public void putFunctionInCache(Function function) {
if(function!=null){
Element element = new Element(function.getName(),(Serializable)function);
/*
if (logger.isDebugEnabled()) {
logger.debug("Cache put: " + element.getKey());
}
*/
cache.put(element);
}else{
logger.info("Function is null");
}
}
public void removeFunctionFromCache(String functionName) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -