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

📄 ehcachefunctinobyname.java

📁 动态实现基于角色的权限管理Acegi+hibernate
💻 JAVA
字号:
package sample.auth.cache.info;

import java.io.Serializable;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataRetrievalFailureException;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Element;
import sample.mappings.function.Function;

public class EhCacheFunctinoByName implements FunctionByNameCache {
	private static final Log logger = LogFactory.getLog(EhCacheFunctinoByName.class);
	private Cache cache;

    //~ Methods ================================================================

    public void setCache(Cache cache) {
        this.cache = cache;
    }

    public Cache getCache() {
        return cache;
    }

	public Function getFunctionByCache(String functionname) {
		 Element element = null;
         logger.info("get Authority by functionname from cache with ");
	        try {
	            element = cache.get(functionname);
	        } catch (CacheException cacheException) {
	            throw new DataRetrievalFailureException("Cache failure: "
	                + cacheException.getMessage());
	        }

	        if (logger.isDebugEnabled()) {
	            logger.debug("Cache hit: " + (element != null) + "; username: "
	                + functionname);
	        }

	        if (element == null) {
	            return null;
	        } else {
	            return (Function) element.getValue();
	        }
	}

	public void putFunctionInCache(Function function) {
		logger.info("put Authority by functionname from cache  ");
		Element element = new Element(function.getName(),(Serializable)function);

        if (logger.isDebugEnabled()) {
            logger.debug("Cache put: " + element.getKey());
        }
        cache.put(element);

	}

	public void removeFunctionFromCache(String functionName) {
		

	}

}

⌨️ 快捷键说明

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