ehcache存取操作

ehcache存取操作

package com.util;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

/**
 * ehcache存取操作
 * 
 * Created by zyb on 2016/8/18.
 */
public class PermitCache {
    private static String cacheName;

    public PermitCache(String cacheName) {
        PermitCache.cacheName = cacheName;
    }

    /**
     * 获取权限的cache配置
     *
     * @return CacheManager对象
     */
    @SuppressWarnings({ "WeakerAccess", "Annotation" })
    public static Cache getCache() {
        CacheManager manager = CacheManager.getInstance();
        return manager.getCache(cacheName);
    }

    /**
     * 存储对象
     *
     * @param strID  ID
     * @param object 对象
     */
    public static void put(String strID, Object object) {
        Element element = new Element("permission_" + strID, object);
        getCache().put(element);
    }

    /**
     * 根据ID获取某缓存对象
     *
     * @param strID ID
     * @return 对象
     */
    public static Object get(String strID) {
        Element element = getCache().get("permission_" + strID);
        if (element == null) {
            return null;
        }
        return element.getObjectValue();
    }

    /**
     * 根据ID删除缓存对象
     *
     * @param strID ID
     * @return boolean
     */
    public static boolean remove(String strID) {
        return getCache().remove("permission_" + strID);
    }
}

 上一篇
cxf与xfire的jar冲突 cxf与xfire的jar冲突
cxf与xfire的jar冲突项目在本地和服务器上面的tomact容器都可以跑,但是在websphere上面出现如下异常,经过调整,发现cxf和xfire的jar包冲突导致,由于项目中用的cxf 2.2故去掉xfire的jar包解决该问题。
2019-08-19
下一篇 
equals 前后null异常 equals 前后null异常
equals 前后null异常如果equals的左边是空值 会出现空指针异常 public class Test { public static void main(String[] args) { String st
2019-08-19
  目录