From 67ccf278676e1333716a98a7a7e493e1fbd461d5 Mon Sep 17 00:00:00 2001 From: xiaofanku Date: Thu, 1 Oct 2020 20:20:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0OnlineMemberEhcacheStorage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ehcache/OnlineMemberEhcacheStorage.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/trident/src/main/java/com/apobates/forum/member/storage/ehcache/OnlineMemberEhcacheStorage.java b/trident/src/main/java/com/apobates/forum/member/storage/ehcache/OnlineMemberEhcacheStorage.java index 99d2f0e..2eca7e6 100644 --- a/trident/src/main/java/com/apobates/forum/member/storage/ehcache/OnlineMemberEhcacheStorage.java +++ b/trident/src/main/java/com/apobates/forum/member/storage/ehcache/OnlineMemberEhcacheStorage.java @@ -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 configuration = new MutableConfiguration() - .setTypes(String.class, MemberSessionBean.class) - .setStoreByValue(true) - .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_DAY)); Cache 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 cache = cacheManager.getCache(EHC_STORE); + Cache 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 cache = cacheManager.getCache(EHC_STORE); + Cache 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(); -- GitLab