master
parent
3839154e79
commit
a56da36a74
2 changed files with 0 additions and 46 deletions
@ -1,11 +0,0 @@ |
|||||||
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); |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,35 +0,0 @@ |
|||||||
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); |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue