提交 67ccf278 编写于 作者: 街头小贩's avatar 街头小贩

更新OnlineMemberEhcacheStorage

上级 62312ee4
......@@ -16,9 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.jcache.JCacheCacheManager;
import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.expiry.CreatedExpiryPolicy;
import javax.cache.expiry.Duration;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -27,7 +24,7 @@ import java.util.Map;
import java.util.Optional;
/**
* 使用Ehcache存储会员在线信息
* @see https://www.ehcache.org/documentation/3.5/107.html
* @see //www.ehcache.org/documentation/3.5/107.html
* @author xiaofanku
* @since 20201001
*/
......@@ -50,13 +47,13 @@ public class OnlineMemberEhcacheStorage implements OnlineMemberStorage {
String ecKey = metaConfig.getName() + ":" + afterPart.get();
CacheManager cacheManager = cacheCacheManager.getCacheManager();
try {
MutableConfiguration<String, MemberSessionBean> configuration = new MutableConfiguration<String, MemberSessionBean>()
.setTypes(String.class, MemberSessionBean.class)
.setStoreByValue(true)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_DAY));
Cache<String, MemberSessionBean> cache = cacheManager.getCache(EHC_STORE, String.class, MemberSessionBean.class);
cache.put(ecKey, memberSessionBean);
cache.close();
}catch(Exception e){
if(logger.isDebugEnabled()){
logger.debug("[OM][EHC][save]"+e.getMessage(), e);
}
}finally {
cacheManager.close();
}
......@@ -71,7 +68,11 @@ public class OnlineMemberEhcacheStorage implements OnlineMemberStorage {
String ecKey = metaConfig.getName() + ":" + afterPart.get();
CacheManager cacheManager = cacheCacheManager.getCacheManager();
try {
cacheManager.getCache(EHC_STORE).remove(ecKey);
cacheManager.getCache(EHC_STORE, String.class, MemberSessionBean.class).remove(ecKey);
}catch(Exception e){
if(logger.isDebugEnabled()){
logger.debug("[OM][EHC][del]"+e.getMessage(), e);
}
}finally {
cacheManager.close();
}
......@@ -97,13 +98,13 @@ public class OnlineMemberEhcacheStorage implements OnlineMemberStorage {
String ecKey = metaConfig.getName() + ":" + afterPart.get();
CacheManager cacheManager = cacheCacheManager.getCacheManager();
try {
Cache<String, MemberSessionBean> cache = cacheManager.getCache(EHC_STORE);
Cache<String, MemberSessionBean> cache = cacheManager.getCache(EHC_STORE, String.class, MemberSessionBean.class);
MemberSessionBean msb = cache.get(ecKey);
cache.close();
return Optional.ofNullable(msb);
}catch(Exception e){
if(logger.isDebugEnabled()){
logger.debug(e.getMessage(), e);
logger.debug("[OM][EHC][get]"+e.getMessage(), e);
}
}finally {
cacheManager.close();
......@@ -120,13 +121,13 @@ public class OnlineMemberEhcacheStorage implements OnlineMemberStorage {
String ecKey = metaConfig.getName() + ":" + afterPart.get();
CacheManager cacheManager = cacheCacheManager.getCacheManager();
try {
Cache<String, MemberSessionBean> cache = cacheManager.getCache(EHC_STORE);
Cache<String, MemberSessionBean> cache = cacheManager.getCache(EHC_STORE, String.class, MemberSessionBean.class);
MemberSessionBean msb = cache.get(ecKey);
cache.put(ecKey, msb.refact(group, role, status));
cache.close();
}catch(Exception e){
if(logger.isDebugEnabled()){
logger.debug(e.getMessage(), e);
logger.debug("[OM][EHC][refresh]"+e.getMessage(), e);
}
}finally {
cacheManager.close();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册