spring 整合了ehcache,包名 spring-context-supportspring
spirng 類 EhCacheCacheManager 引用了 ehcache 中 CacheManager 類,以達到內存的目的app
代碼 ide
public class EhcacheManager implements CacheManager {this
private Logger log = Logger.getLogger(this.getClass());.net
private EhCacheCacheManager springEhcacheManager;內存
private String cacheName;get
@Override
public void put(String key, Object value, int timeToLive) {
try {
getCache().put(key, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}io
@Override
public boolean add(String key, Object value, int timeToLive) {
try {
getCache().put(key, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
}class
return true;
}引用
@Override
public Object get(String key) {
try {
Cache.ValueWrapper value = getCache().get(key);
if (value == null) {
return null;
}
return getCache().get(key).get();
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
@Override
public Object getAndTouch(String key, int timeToLive) {
return get(key);
}
@Override
public void delete(String key) {
try {
getCache().evict(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
@Override
public boolean containsKey(String key) {
try {
Cache.ValueWrapper value = getCache().get(key);
return value != null;
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
public EhCacheCacheManager getSpringEhcacheManager() {
return springEhcacheManager;
}
public void setSpringEhcacheManager(EhCacheCacheManager springEhcacheManager) {
this.springEhcacheManager = springEhcacheManager;
}
public String getCacheName() {
return cacheName;
}
public void setCacheName(String cacheName) {
this.cacheName = cacheName;
}
private Cache getCache(){ return springEhcacheManager.getCache(cacheName); } }