Commit a56da36a authored by guwd's avatar guwd

删除

parent 3839154e
package net.mingsoft.cms.biz;
public interface ICacheBiz {
void set(String cacheName, String key, Object value);
<T> T get(String cacheName, String key, Class<T> cls);
void del(String cacheName, String key);
}
\ No newline at end of file
package net.mingsoft.cms.biz.impl;
import com.alibaba.fastjson.JSONObject;
import net.mingsoft.cms.biz.ICacheBiz;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
@Service("abc")
public class EhcacheBizImpl implements ICacheBiz {
@Autowired
private CacheManager cacheManager;
@Override
public void set(String cacheName, String key, Object value) {
this.cacheManager.getCache(cacheName).put(key, JSONObject.toJSONString(value));
}
@Override
public <T> T get(String cacheName, String key, Class<T> cls) {
String str = this.cacheManager.getCache(cacheName).get(key, String.class);
if (StringUtils.isBlank(str)) {
return null;
}
return JSONObject.parseObject(str, cls);
}
@Override
public void del(String cacheName, String key) {
this.cacheManager.getCache(cacheName).evictIfPresent(key);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment