{"id":251350,"date":"2022-09-09T08:04:28","date_gmt":"2022-09-09T00:04:28","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=251350"},"modified":"2022-08-29T09:05:42","modified_gmt":"2022-08-29T01:05:42","slug":"redis-linux-ten","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redis-linux-ten.html","title":{"rendered":"redis\u7f13\u5b58\u4e00\u81f4\u6027\u5ef6\u65f6\u53cc\u5220\u4ee3\u7801\u5b9e\u73b0\u65b9\u5f0f\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86redis\u7f13\u5b58\u4e00\u81f4\u6027\u5ef6\u65f6\u53cc\u5220\u4ee3\u7801\u5b9e\u73b0\u65b9\u5f0f\uff0c\u5177\u6709\u5f88\u597d\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002\u5982\u6709\u9519\u8bef\u6216\u672a\u8003\u8651\u5b8c\u5168\u7684\u5730\u65b9\uff0c\u671b\u4e0d\u541d\u8d50\u6559<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
redis\u7f13\u5b58\u4e00\u81f4\u6027\u5ef6\u65f6\u53cc\u5220\u4ee3\u7801<\/strong><\/div>\n

\u4e0d\u5e9f\u8bdd\u3001\u3001\u3001\u5982\u4e0b<\/p>\n

1\u3001\u81ea\u5b9a\u4e49\u6ce8\u89e3<\/strong><\/span><\/div>\n
\/**\r\n*@author caoyue\r\n*\u5ef6\u65f6\u53cc\u5220\r\n**\/\r\n@Retention(RetentionPolicy.RUNTIME)\r\n@Documented\r\n@Target(ElementType.METHOD)\r\npublic @interface ClearCache {\r\n    boolean open() default true;\r\n}<\/pre>\n
2\u3001\u522a\u9664\u903b\u8f91<\/strong><\/span><\/div>\n
\/**\r\n * @author caoyue\r\n *\/\r\n@Component\r\n@Aspect\r\n@Slf4j\r\npublic class DoubleClearCacheAop {\r\n    @Autowired\r\n    private UserService userService;\r\n    \/\/\u58f0\u660e\u4e00\u4e2a\u7528\u4e8e\u5ef6\u65f6\u7684\u5b9a\u65f6\u7ebf\u7a0b\u6c60\u4ee3\u66ff\u7ebf\u7a0bsleep\r\n    ScheduledExecutorService task = new ScheduledThreadPoolExecutor(10, new BasicThreadFactory.\r\n            Builder().namingPattern(\"clearCache-schedule-pool-%d\").build());\r\n    @Pointcut(\"@annotation(com.inspur.henan.uac.modules.open.util.ClearCache)\")\r\n    private void clearCachePoint() {\r\n    }\r\n    @Around(\"clearCachePoint()\")\r\n    public Object clearCacheAop(ProceedingJoinPoint proceeds) throws Throwable {\r\n        Method method = ((MethodSignature) proceeds.getSignature()).getMethod();\r\n        ClearCache annotation = method.getAnnotation(ClearCache.class);\r\n        Object proceed = null;\r\n        \/\/\u5982\u679c\u6e05\u9664\u6ce8\u89e3\u5f00\u542f\u4e86\r\n        if (annotation.open()) {\r\n            \/\/\u4e0a\u4e0b\u6587\u83b7\u53d6\u4fe1\u606f\r\n            IPubUser user = MsySecurityContextHolder.getUser();\r\n            if (Objects.nonNull(user)) {\r\n                \/\/\u6267\u884c\u6e05\u9664\u7f13\u5b58\u7684\u52a8\u4f5c\r\n                userService._clearCache(user);\r\n                \/\/\u4e1a\u52a1\u5904\u7406\r\n                proceed = proceeds.proceed();\r\n                \/\/\u5ef6\u65f6\u4e24\u79d2\u540e\u518d\u5220\r\n                task.schedule(() -> {\r\n                    userService._clearCache(user);\r\n                    if (log.isInfoEnabled()) {\r\n                        log.info(Thread.currentThread().getName() + \":double delete cache completed\");\r\n                    }\r\n                }, 2L, TimeUnit.SECONDS);\r\n            } else {\r\n                proceed = proceeds.proceed();\r\n            }\r\n        }\r\n        return proceed;\r\n    }\r\n}<\/pre>\n
redis\u7f13\u5b58\u5ef6\u8fdf\u53cc\u5220\u95ee\u9898<\/strong><\/div>\n

\u9ad8\u5e76\u53d1\u573a\u666f\u4f7f\u7528redis\u4f5c\u4e3a\u7f13\u5b58\u5b58\u50a8\u6570\u636e\uff0c\u5f53\u6570\u636e\u66f4\u65b0\u65f6\uff0c\u5982\u4f55\u4fdd\u8bc1\u7f13\u5b58\u4e00\u81f4\u6027\uff0c<\/p>\n

\u5ef6\u8fdf\u53cc\u5220\u7684\u7b56\u7565\uff1a<\/p>\n

\u5148\u5220\u9664\u7f13\u5b58\uff0c\u7136\u540e\u66f4\u65b0\u6570\u636e\u5e93\u6570\u636e\uff0c\u4f11\u7720sleep\uff0c\u6700\u540e\u518d\u6b21\u5220\u9664\u7f13\u5b58\u6570\u636e\u3002<\/p>\n

\u4f11\u7720\u7684\u65f6\u95f4\u7565\u5fae\u5927\u4e8e\u4ece\u6570\u636e\u5e93\u67e5\u8be2\u6570\u636e\u7684\u65f6\u95f4\u3002<\/p>\n

\u5f53\u8bfb\u5199\u5206\u79bb\u65f6\uff0c\u8003\u8651\u5230\u4e3b\u4ece\u6570\u636e\u540c\u6b65\u5ef6\u8fdf\uff0c\u4f11\u7720\u65f6\u95f4\u7ea61s\u3002<\/p>\n

\u4f11\u7720\u65f6\u95f4\u4e0d\u80fd\u592a\u5927\uff0c\u5426\u5219\u4f1a\u5f71\u54cd\u66f4\u65b0\u7684\u901f\u5ea6\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e0d\u5e9f\u8bdd\u3001\u3001\u3001\u5982\u4e0b \/** *@author caoyue *\u5ef6\u65f6\u53cc\u5220 **\/ @Retention(Reten […]<\/p>\n","protected":false},"author":1482,"featured_media":84130,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-251350","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=251350"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251350\/revisions"}],"predecessor-version":[{"id":251353,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251350\/revisions\/251353"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/84130"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=251350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=251350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=251350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}