From c3b64048bdc5e25fb679bc78ffbaeb30f161b398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8B=89=E8=BF=AA=E7=BB=B4?= Date: Mon, 13 Sep 2021 14:28:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=20platform=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84=20Redis=20=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、修改了 Service 支持多个 platform 参数下可能出现的缓存清理不正确的问题 2、设置缓存Key的生成策略未:GNSCache#{platform}# 开头 --- .../impl/SysNotificationServiceImpl.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java index 56a2b09..3324ffa 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java @@ -1,6 +1,5 @@ package cn.org.gitlink.notification.model.service.notification.impl; -import cn.org.gitlink.notification.common.constant.NotificationSystemConstant; import cn.org.gitlink.notification.common.utils.RedisUtil; import cn.org.gitlink.notification.model.dao.entity.SysNotification; import cn.org.gitlink.notification.model.dao.entity.vo.NewSysNotificationVo; @@ -19,7 +18,7 @@ import java.util.List; @Service(value = "SysNotificationServiceImpl") public class SysNotificationServiceImpl extends ServiceImpl implements SysNotificationService { - private static final String CACHE_KEY_PREFFIX = "GITLINK-CACHE#R"; + private static final String CACHE_KEY_PREFFIX = "GNSCache#"; @Autowired @@ -40,7 +39,7 @@ public class SysNotificationServiceImpl extends ServiceImpl 0) { - this.delUserCache(receiver); + this.delUserCache(platform, receiver); } return count; } @Override public int getUnreadNotificationCount(String platform, Integer receiver) throws Exception { - String KEY_ALL_COUNT = CACHE_KEY_PREFFIX + receiver + "#COUNT"; + String KEY_ALL_COUNT = CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "#COUNT"; Object foundResult = this.redisUtil.get(KEY_ALL_COUNT); if (foundResult != null) { return (Integer) foundResult; @@ -68,7 +67,7 @@ public class SysNotificationServiceImpl extends ServiceImpl getUnreadNotificationByType(String platform, Integer receiver, Integer size, Integer type) throws Exception { - String KEY_TYPE_LIST = CACHE_KEY_PREFFIX + receiver + "#T" + type + "#LIST"; + String KEY_TYPE_LIST = CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "#T" + type + "#LIST"; Object foundResult = this.redisUtil.get(KEY_TYPE_LIST); if (foundResult != null) { return (List) foundResult; @@ -80,7 +79,7 @@ public class SysNotificationServiceImpl extends ServiceImpl getNotification(int type, int page, int size, String orderBy, String platform, Integer receiver) throws Exception { - String KEY_PAGE_LIST = CACHE_KEY_PREFFIX + receiver + "P" + page + "S" + size + "T" + type + "#LIST"; + String KEY_PAGE_LIST = CACHE_KEY_PREFFIX + platform.toUpperCase() + "#" + receiver + "P" + page + "S" + size + "T" + type + "#LIST"; Object foundResult = this.redisUtil.get(KEY_PAGE_LIST); if (foundResult != null) { return (Page) foundResult; @@ -109,7 +108,7 @@ public class SysNotificationServiceImpl extends ServiceImpl