ehcache存取操作
package com.util;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class PermitCache {
private static String cacheName;
public PermitCache(String cacheName) {
PermitCache.cacheName = cacheName;
}
@SuppressWarnings({ "WeakerAccess", "Annotation" })
public static Cache getCache() {
CacheManager manager = CacheManager.getInstance();
return manager.getCache(cacheName);
}
public static void put(String strID, Object object) {
Element element = new Element("permission_" + strID, object);
getCache().put(element);
}
public static Object get(String strID) {
Element element = getCache().get("permission_" + strID);
if (element == null) {
return null;
}
return element.getObjectValue();
}
public static boolean remove(String strID) {
return getCache().remove("permission_" + strID);
}
}