From 52ca46f07a5aaed96ddbc72bcb002c04af678cf8 Mon Sep 17 00:00:00 2001 From: liumaobudao <619853006@qq.com> Date: Fri, 25 Sep 2020 10:41:40 +0800 Subject: [PATCH 1/7] no commit message --- .../plugins/wkcache/WkcacheAopConfigure.java | 13 ++-- .../WkcacheNamesRemoveAllInterceptor.java | 36 +++++++++ .../WkcacheNamesRemoveEntryInterceptor.java | 74 +++++++++++++++++++ .../wkcache/annotation/CacheNamesRemove.java | 14 ++++ .../annotation/CacheNamesRemoveAll.java | 14 ++++ .../plugins/wkcache/test/MyCacheTest.java | 35 +++++++++ .../plugins/wkcache/test/WkcacheTest.java | 26 +++++-- 7 files changed, 199 insertions(+), 13 deletions(-) create mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java create mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java create mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java create mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java index 21183e93..328ec347 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java @@ -5,10 +5,7 @@ import org.nutz.ioc.Ioc; import org.nutz.ioc.aop.config.AopConfigration; import org.nutz.ioc.aop.config.InterceptorPair; import org.nutz.ioc.loader.annotation.IocBean; -import org.nutz.plugins.wkcache.annotation.CacheRemove; -import org.nutz.plugins.wkcache.annotation.CacheRemoveAll; -import org.nutz.plugins.wkcache.annotation.CacheResult; -import org.nutz.plugins.wkcache.annotation.CacheUpdate; +import org.nutz.plugins.wkcache.annotation.*; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -28,7 +25,9 @@ public class WkcacheAopConfigure implements AopConfigration { if (method.getAnnotation(CacheResult.class) != null || method.getAnnotation(CacheUpdate.class) != null || method.getAnnotation(CacheRemove.class) != null - || method.getAnnotation(CacheRemoveAll.class) != null) { + || method.getAnnotation(CacheRemoveAll.class) != null + || method.getAnnotation(CacheNamesRemove.class) != null + || method.getAnnotation(CacheNamesRemoveAll.class)!=null) { flag = false; break; } @@ -43,6 +42,10 @@ public class WkcacheAopConfigure implements AopConfigration { new WkcacheMethodMatcher(CacheRemove.class))); list.add(new InterceptorPair(ioc.get(WkcacheRemoveAllInterceptor.class), new WkcacheMethodMatcher(CacheRemoveAll.class))); + list.add(new InterceptorPair(ioc.get(WkcacheNamesRemoveEntryInterceptor.class), + new WkcacheMethodMatcher(CacheNamesRemove.class))); + list.add(new InterceptorPair(ioc.get(WkcacheNamesRemoveAllInterceptor.class), + new WkcacheMethodMatcher(CacheNamesRemoveAll.class))); return list; } } diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java new file mode 100644 index 00000000..b6cc9cac --- /dev/null +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java @@ -0,0 +1,36 @@ +package org.nutz.plugins.wkcache; + +import org.nutz.aop.InterceptorChain; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.Strings; +import org.nutz.plugins.wkcache.annotation.CacheDefaults; +import org.nutz.plugins.wkcache.annotation.CacheNamesRemoveAll; +import org.nutz.plugins.wkcache.annotation.CacheRemoveAll; + +import java.lang.reflect.Method; +import java.util.Set; + +/** + * Created by wizzer on 2017/6/14. + */ +@IocBean(singleton = false) +public class WkcacheNamesRemoveAllInterceptor extends AbstractWkcacheInterceptor { + + public void filter(InterceptorChain chain) throws Throwable { + Method method = chain.getCallingMethod(); + CacheNamesRemoveAll cacheNamesRemoveAll = method.getAnnotation(CacheNamesRemoveAll.class); + String[] cacheNames = cacheNamesRemoveAll!=null&&cacheNamesRemoveAll.cacheNames()!=null?cacheNamesRemoveAll.cacheNames():new String[]{""}; + for (String cacheName : cacheNames) { + if (Strings.isBlank(cacheName)) { + CacheDefaults cacheDefaults = method.getDeclaringClass() + .getAnnotation(CacheDefaults.class); + cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; + } + Set set = redisService().keys((cacheName + ":*").getBytes()); + for (byte[] it : set) { + redisService().del(it); + } + } + chain.doChain(); + } +} diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java new file mode 100644 index 00000000..e6268822 --- /dev/null +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java @@ -0,0 +1,74 @@ +package org.nutz.plugins.wkcache; + +import org.nutz.aop.InterceptorChain; +import org.nutz.el.El; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.Lang; +import org.nutz.lang.Strings; +import org.nutz.lang.segment.CharSegment; +import org.nutz.lang.util.Context; +import org.nutz.lang.util.MethodParamNamesScaner; +import org.nutz.plugins.wkcache.annotation.CacheDefaults; +import org.nutz.plugins.wkcache.annotation.CacheNamesRemove; +import org.nutz.plugins.wkcache.annotation.CacheRemove; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +/** + * Created by wizzer on 2017/6/14. + */ +@IocBean(singleton = false) +public class WkcacheNamesRemoveEntryInterceptor extends AbstractWkcacheInterceptor { + + public void filter(InterceptorChain chain) throws Throwable { + Method method = chain.getCallingMethod(); + CacheNamesRemove cacheNamesRemove = method.getAnnotation(CacheNamesRemove.class); + for (CacheRemove cacheRemove : cacheNamesRemove.cacheNames()) { + String cacheKey = Strings.sNull(cacheRemove.cacheKey()); + String cacheName = Strings.sNull(cacheRemove.cacheName()); + if (Strings.isBlank(cacheKey)) { + cacheKey = method.getDeclaringClass().getName() + + "." + + method.getName() + + "#" + + Arrays.toString(chain.getArgs()); + } else { + this.key = new CharSegment(cacheKey); + if (key.hasKey()) { + Context ctx = Lang.context(); + Object[] args = chain.getArgs(); + List names = MethodParamNamesScaner.getParamNames(method);//不支持nutz低于1.60的版本 + if (names != null) { + for (int i = 0; i < names.size() && i < args.length; i++) { + ctx.set(names.get(i), args[i]); + } + } + ctx.set("args", args); + Context _ctx = Lang.context(); + for (String key : key.keys()) { + _ctx.set(key, new El(key).eval(ctx)); + } + cacheKey = key.render(_ctx).toString(); + } else { + cacheKey = key.getOrginalString(); + } + } + if (Strings.isBlank(cacheName)) { + CacheDefaults cacheDefaults = method.getDeclaringClass() + .getAnnotation(CacheDefaults.class); + cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; + } + if (cacheKey.endsWith("*")) { + Set set = redisService().keys((cacheName + ":" + cacheKey).getBytes()); + for (byte[] it : set) { + redisService().del(it); + } + } else + redisService().del((cacheName + ":" + cacheKey).getBytes()); + } + chain.doChain(); + } +} diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java new file mode 100644 index 00000000..1b27db12 --- /dev/null +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java @@ -0,0 +1,14 @@ +package org.nutz.plugins.wkcache.annotation; + +import java.lang.annotation.*; + +/** + * Created by wizzer on 2017/6/14. + */ +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface CacheNamesRemove { + CacheRemove[] cacheNames() default {}; +} diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java new file mode 100644 index 00000000..ea28730d --- /dev/null +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java @@ -0,0 +1,14 @@ +package org.nutz.plugins.wkcache.annotation; + +import java.lang.annotation.*; + +/** + * Created by wizzer on 2017/6/14. + */ +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface CacheNamesRemoveAll { + String[] cacheNames() default {}; +} diff --git a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java index 4f935d6a..b4edabed 100644 --- a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java +++ b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java @@ -21,6 +21,11 @@ public class MyCacheTest { return txt; } + @CacheResult(cacheName = "cache_time_3",cacheKey = "test") + public Object cache_time_3(String txt) { + return txt; + } + @CacheResult(cacheKey = "test") public Object testCache(String txt) { return txt; @@ -36,6 +41,24 @@ public class MyCacheTest { System.out.println("我被执行了..."); return test; } + @CacheResult(cacheName = "cache_time_1",cacheKey = "${test.id}_${test.name}") + public Object testCacheObj1(TestBean test) { + System.out.println("我被执行了1..."); + return test; + } + + @CacheResult(cacheName = "cache_time_2",cacheKey = "${test.id}_${test.name}") + public Object testCacheObj2(TestBean test) { + System.out.println("我被执行了2..."); + return test; + } + @CacheResult(cacheName = "cache_time_3",cacheKey = "${test.id}_${test.name}") + public Object testCacheObj3(TestBean test) { + System.out.println("我被执行了3..."); + return test; + } + + @CacheResult public Object testCacheList(List test) { @@ -58,8 +81,20 @@ public class MyCacheTest { } + @CacheNamesRemove(cacheNames={ + @CacheRemove(cacheName = "cache_time_1",cacheKey = "${test.id}_${test.name}"), + @CacheRemove(cacheName = "cache_time_2",cacheKey = "${test.id}_${test.name}") + }) + public void testNamesRemove(TestBean test) { + + } + @CacheRemoveAll() public void testRemoveAll() { + } + @CacheNamesRemoveAll(cacheNames = {"cache_time_1","cache_time_3"}) + public void testNamesRemoveAll() { + } } diff --git a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java index 76e798b3..8f12b9b1 100644 --- a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java +++ b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java @@ -8,6 +8,7 @@ import org.nutz.ioc.impl.PropertiesProxy; import org.nutz.ioc.loader.combo.ComboIocLoader; import org.nutz.log.Log; import org.nutz.log.Logs; +import org.nutz.plugins.wkcache.annotation.CacheNamesRemoveAll; /** * Created by wizzer on 2017/6/14. @@ -24,21 +25,30 @@ public class WkcacheTest extends Assert { conf.put("wkcache.nutzwk_cache", "1800"); conf.put("wkcache.cache_time_1", "18000"); conf.put("wkcache.cache_time_2", "28000"); + conf.put("redis.password", "123456"); ioc.getIocContext().save("app", "conf", new ObjectProxy(conf)); assertTrue(ioc.getNames().length > 0); log.debug(ioc.get(MyCacheTest.class).testCache("wizzer.cn")); // ioc.get(MyCacheTest.class).testRemove(); -// log.debug(ioc.get(MyCacheTest.class).testCache("大鲨鱼最帅")); -// ioc.get(MyCacheTest.class).testRemoveAll(); -// log.debug(ioc.get(MyCacheTest.class).testCacheEl("el")); + log.debug(ioc.get(MyCacheTest.class).testCache("大鲨鱼最帅")); + ioc.get(MyCacheTest.class).testRemoveAll(); + log.debug(ioc.get(MyCacheTest.class).cache_time_1("大鲨鱼最帅")); + log.debug(ioc.get(MyCacheTest.class).cache_time_2("大鲨鱼最帅2")); + log.debug(ioc.get(MyCacheTest.class).cache_time_3("大鲨鱼最帅3")); +// ioc.get(MyCacheTest.class).testNamesRemoveAll(); + TestBean test = new TestBean(); test.setId("abc"); test.setName("def"); - for (int i = 0; i < 1000; i++) - log.debug(ioc.get(MyCacheTest.class).testCacheObj(test)); -// ioc.get(MyCacheTest.class).testRemove(test); - ioc.get(MyCacheTest.class).cache_time_1("hello1"); - ioc.get(MyCacheTest.class).cache_time_2("hello2"); +// for (int i = 0; i < 1000; i++) +// log.debug(ioc.get(MyCacheTest.class).testCacheObj(test)); + log.debug(ioc.get(MyCacheTest.class).testCacheObj1(test)); + log.debug(ioc.get(MyCacheTest.class).testCacheObj2(test)); + log.debug(ioc.get(MyCacheTest.class).testCacheObj3(test)); + ioc.get(MyCacheTest.class).testNamesRemove(test); + ioc.get(MyCacheTest.class).testNamesRemoveAll(); +// ioc.get(MyCacheTest.class).cache_time_1("hello1"); +// ioc.get(MyCacheTest.class).cache_time_2("hello2"); } -- Gitee From 18c70f32cb847acdb70458753ac0baa4594072a0 Mon Sep 17 00:00:00 2001 From: liumaobudao <619853006@qq.com> Date: Fri, 25 Sep 2020 15:00:12 +0800 Subject: [PATCH 2/7] no commit message --- .../plugins/wkcache/WkcacheAopConfigure.java | 8 +- .../WkcacheNamesRemoveAllInterceptor.java | 36 --------- .../WkcacheNamesRemoveEntryInterceptor.java | 74 ------------------- .../wkcache/WkcacheRemoveAllInterceptor.java | 10 ++- .../wkcache/annotation/CacheNamesRemove.java | 14 ---- .../annotation/CacheNamesRemoveAll.java | 14 ---- 6 files changed, 8 insertions(+), 148 deletions(-) delete mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java delete mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java delete mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java delete mode 100644 nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java index 328ec347..039476ac 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java @@ -25,9 +25,7 @@ public class WkcacheAopConfigure implements AopConfigration { if (method.getAnnotation(CacheResult.class) != null || method.getAnnotation(CacheUpdate.class) != null || method.getAnnotation(CacheRemove.class) != null - || method.getAnnotation(CacheRemoveAll.class) != null - || method.getAnnotation(CacheNamesRemove.class) != null - || method.getAnnotation(CacheNamesRemoveAll.class)!=null) { + || method.getAnnotation(CacheRemoveAll.class) != null) { flag = false; break; } @@ -42,10 +40,6 @@ public class WkcacheAopConfigure implements AopConfigration { new WkcacheMethodMatcher(CacheRemove.class))); list.add(new InterceptorPair(ioc.get(WkcacheRemoveAllInterceptor.class), new WkcacheMethodMatcher(CacheRemoveAll.class))); - list.add(new InterceptorPair(ioc.get(WkcacheNamesRemoveEntryInterceptor.class), - new WkcacheMethodMatcher(CacheNamesRemove.class))); - list.add(new InterceptorPair(ioc.get(WkcacheNamesRemoveAllInterceptor.class), - new WkcacheMethodMatcher(CacheNamesRemoveAll.class))); return list; } } diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java deleted file mode 100644 index b6cc9cac..00000000 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveAllInterceptor.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.nutz.plugins.wkcache; - -import org.nutz.aop.InterceptorChain; -import org.nutz.ioc.loader.annotation.IocBean; -import org.nutz.lang.Strings; -import org.nutz.plugins.wkcache.annotation.CacheDefaults; -import org.nutz.plugins.wkcache.annotation.CacheNamesRemoveAll; -import org.nutz.plugins.wkcache.annotation.CacheRemoveAll; - -import java.lang.reflect.Method; -import java.util.Set; - -/** - * Created by wizzer on 2017/6/14. - */ -@IocBean(singleton = false) -public class WkcacheNamesRemoveAllInterceptor extends AbstractWkcacheInterceptor { - - public void filter(InterceptorChain chain) throws Throwable { - Method method = chain.getCallingMethod(); - CacheNamesRemoveAll cacheNamesRemoveAll = method.getAnnotation(CacheNamesRemoveAll.class); - String[] cacheNames = cacheNamesRemoveAll!=null&&cacheNamesRemoveAll.cacheNames()!=null?cacheNamesRemoveAll.cacheNames():new String[]{""}; - for (String cacheName : cacheNames) { - if (Strings.isBlank(cacheName)) { - CacheDefaults cacheDefaults = method.getDeclaringClass() - .getAnnotation(CacheDefaults.class); - cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; - } - Set set = redisService().keys((cacheName + ":*").getBytes()); - for (byte[] it : set) { - redisService().del(it); - } - } - chain.doChain(); - } -} diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java deleted file mode 100644 index e6268822..00000000 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheNamesRemoveEntryInterceptor.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.nutz.plugins.wkcache; - -import org.nutz.aop.InterceptorChain; -import org.nutz.el.El; -import org.nutz.ioc.loader.annotation.IocBean; -import org.nutz.lang.Lang; -import org.nutz.lang.Strings; -import org.nutz.lang.segment.CharSegment; -import org.nutz.lang.util.Context; -import org.nutz.lang.util.MethodParamNamesScaner; -import org.nutz.plugins.wkcache.annotation.CacheDefaults; -import org.nutz.plugins.wkcache.annotation.CacheNamesRemove; -import org.nutz.plugins.wkcache.annotation.CacheRemove; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -/** - * Created by wizzer on 2017/6/14. - */ -@IocBean(singleton = false) -public class WkcacheNamesRemoveEntryInterceptor extends AbstractWkcacheInterceptor { - - public void filter(InterceptorChain chain) throws Throwable { - Method method = chain.getCallingMethod(); - CacheNamesRemove cacheNamesRemove = method.getAnnotation(CacheNamesRemove.class); - for (CacheRemove cacheRemove : cacheNamesRemove.cacheNames()) { - String cacheKey = Strings.sNull(cacheRemove.cacheKey()); - String cacheName = Strings.sNull(cacheRemove.cacheName()); - if (Strings.isBlank(cacheKey)) { - cacheKey = method.getDeclaringClass().getName() - + "." - + method.getName() - + "#" - + Arrays.toString(chain.getArgs()); - } else { - this.key = new CharSegment(cacheKey); - if (key.hasKey()) { - Context ctx = Lang.context(); - Object[] args = chain.getArgs(); - List names = MethodParamNamesScaner.getParamNames(method);//不支持nutz低于1.60的版本 - if (names != null) { - for (int i = 0; i < names.size() && i < args.length; i++) { - ctx.set(names.get(i), args[i]); - } - } - ctx.set("args", args); - Context _ctx = Lang.context(); - for (String key : key.keys()) { - _ctx.set(key, new El(key).eval(ctx)); - } - cacheKey = key.render(_ctx).toString(); - } else { - cacheKey = key.getOrginalString(); - } - } - if (Strings.isBlank(cacheName)) { - CacheDefaults cacheDefaults = method.getDeclaringClass() - .getAnnotation(CacheDefaults.class); - cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; - } - if (cacheKey.endsWith("*")) { - Set set = redisService().keys((cacheName + ":" + cacheKey).getBytes()); - for (byte[] it : set) { - redisService().del(it); - } - } else - redisService().del((cacheName + ":" + cacheKey).getBytes()); - } - chain.doChain(); - } -} diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java index c6b8e5cd..a85f819f 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java @@ -24,9 +24,13 @@ public class WkcacheRemoveAllInterceptor extends AbstractWkcacheInterceptor { .getAnnotation(CacheDefaults.class); cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; } - Set set = redisService().keys((cacheName + ":*").getBytes()); - for (byte[] it : set) { - redisService().del(it); + for (String s : cacheName.split(",|;")) {//支持多个cacheName + if(Strings.isNotBlank(s)){ + Set set = redisService().keys((s + ":*").getBytes()); + for (byte[] it : set) { + redisService().del(it); + } + } } chain.doChain(); } diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java deleted file mode 100644 index 1b27db12..00000000 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemove.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.nutz.plugins.wkcache.annotation; - -import java.lang.annotation.*; - -/** - * Created by wizzer on 2017/6/14. - */ -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -public @interface CacheNamesRemove { - CacheRemove[] cacheNames() default {}; -} diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java deleted file mode 100644 index ea28730d..00000000 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/annotation/CacheNamesRemoveAll.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.nutz.plugins.wkcache.annotation; - -import java.lang.annotation.*; - -/** - * Created by wizzer on 2017/6/14. - */ -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -public @interface CacheNamesRemoveAll { - String[] cacheNames() default {}; -} -- Gitee From f9ec84c684f6d06323da1dd0059c02cbe9af1ba4 Mon Sep 17 00:00:00 2001 From: liumaobudao <619853006@qq.com> Date: Fri, 25 Sep 2020 15:03:22 +0800 Subject: [PATCH 3/7] no commit message --- .../org/nutz/plugins/wkcache/test/MyCacheTest.java | 14 +------------- .../org/nutz/plugins/wkcache/test/WkcacheTest.java | 6 ++---- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java index b4edabed..443db464 100644 --- a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java +++ b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/MyCacheTest.java @@ -81,20 +81,8 @@ public class MyCacheTest { } - @CacheNamesRemove(cacheNames={ - @CacheRemove(cacheName = "cache_time_1",cacheKey = "${test.id}_${test.name}"), - @CacheRemove(cacheName = "cache_time_2",cacheKey = "${test.id}_${test.name}") - }) - public void testNamesRemove(TestBean test) { - - } - - @CacheRemoveAll() + @CacheRemoveAll(cacheName = "cache_time_1,cache_time_3;cache_time_2") public void testRemoveAll() { - } - @CacheNamesRemoveAll(cacheNames = {"cache_time_1","cache_time_3"}) - public void testNamesRemoveAll() { - } } diff --git a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java index 8f12b9b1..a9c49b63 100644 --- a/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java +++ b/nutz-plugins-wkcache/src/test/java/org/nutz/plugins/wkcache/test/WkcacheTest.java @@ -8,7 +8,6 @@ import org.nutz.ioc.impl.PropertiesProxy; import org.nutz.ioc.loader.combo.ComboIocLoader; import org.nutz.log.Log; import org.nutz.log.Logs; -import org.nutz.plugins.wkcache.annotation.CacheNamesRemoveAll; /** * Created by wizzer on 2017/6/14. @@ -35,7 +34,7 @@ public class WkcacheTest extends Assert { log.debug(ioc.get(MyCacheTest.class).cache_time_1("大鲨鱼最帅")); log.debug(ioc.get(MyCacheTest.class).cache_time_2("大鲨鱼最帅2")); log.debug(ioc.get(MyCacheTest.class).cache_time_3("大鲨鱼最帅3")); -// ioc.get(MyCacheTest.class).testNamesRemoveAll(); +// TestBean test = new TestBean(); test.setId("abc"); @@ -45,8 +44,7 @@ public class WkcacheTest extends Assert { log.debug(ioc.get(MyCacheTest.class).testCacheObj1(test)); log.debug(ioc.get(MyCacheTest.class).testCacheObj2(test)); log.debug(ioc.get(MyCacheTest.class).testCacheObj3(test)); - ioc.get(MyCacheTest.class).testNamesRemove(test); - ioc.get(MyCacheTest.class).testNamesRemoveAll(); + ioc.get(MyCacheTest.class).testRemoveAll(); // ioc.get(MyCacheTest.class).cache_time_1("hello1"); // ioc.get(MyCacheTest.class).cache_time_2("hello2"); } -- Gitee From acf241c901125789a31ef203ca077da5fd70383c Mon Sep 17 00:00:00 2001 From: liumaobudao <619853006@qq.com> Date: Fri, 25 Sep 2020 15:06:44 +0800 Subject: [PATCH 4/7] no commit message --- .../org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java index a85f819f..72f0391b 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java @@ -24,7 +24,7 @@ public class WkcacheRemoveAllInterceptor extends AbstractWkcacheInterceptor { .getAnnotation(CacheDefaults.class); cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; } - for (String s : cacheName.split(",|;")) {//支持多个cacheName + for (String s : cacheName.split(",")) { if(Strings.isNotBlank(s)){ Set set = redisService().keys((s + ":*").getBytes()); for (byte[] it : set) { -- Gitee From 8cff16ac87413dda2a31bff60414da6c744e8dae Mon Sep 17 00:00:00 2001 From: liumaobudao <619853006@qq.com> Date: Fri, 25 Sep 2020 15:09:35 +0800 Subject: [PATCH 5/7] no commit message --- .../java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java | 6 +++++- .../nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java index 039476ac..7c7bb2ab 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheAopConfigure.java @@ -5,7 +5,11 @@ import org.nutz.ioc.Ioc; import org.nutz.ioc.aop.config.AopConfigration; import org.nutz.ioc.aop.config.InterceptorPair; import org.nutz.ioc.loader.annotation.IocBean; -import org.nutz.plugins.wkcache.annotation.*; +import org.nutz.plugins.wkcache.annotation.CacheRemove; +import org.nutz.plugins.wkcache.annotation.CacheRemoveAll; +import org.nutz.plugins.wkcache.annotation.CacheResult; +import org.nutz.plugins.wkcache.annotation.CacheUpdate; + import java.lang.annotation.Annotation; import java.lang.reflect.Method; diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java index 72f0391b..7a2a9f9e 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java @@ -25,7 +25,7 @@ public class WkcacheRemoveAllInterceptor extends AbstractWkcacheInterceptor { cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; } for (String s : cacheName.split(",")) { - if(Strings.isNotBlank(s)){ + if (Strings.isNotBlank(s)) { Set set = redisService().keys((s + ":*").getBytes()); for (byte[] it : set) { redisService().del(it); -- Gitee From e6b45f2052e4c41409e1bb8099edd698fe9d8287 Mon Sep 17 00:00:00 2001 From: liumaobudao <619853006@qq.com> Date: Fri, 25 Sep 2020 15:13:44 +0800 Subject: [PATCH 6/7] no commit message --- .../org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java index 7a2a9f9e..0a6cb654 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java @@ -24,7 +24,7 @@ public class WkcacheRemoveAllInterceptor extends AbstractWkcacheInterceptor { .getAnnotation(CacheDefaults.class); cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; } - for (String s : cacheName.split(",")) { + for (String s : cacheName.split(",|;")) { if (Strings.isNotBlank(s)) { Set set = redisService().keys((s + ":*").getBytes()); for (byte[] it : set) { -- Gitee From a8e955411c0d7153815b102110d94a83e7a730f2 Mon Sep 17 00:00:00 2001 From: liumaobudao <619853006@qq.com> Date: Fri, 25 Sep 2020 15:24:16 +0800 Subject: [PATCH 7/7] no commit message --- .../org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java index 0a6cb654..7a2a9f9e 100644 --- a/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java +++ b/nutz-plugins-wkcache/src/main/java/org/nutz/plugins/wkcache/WkcacheRemoveAllInterceptor.java @@ -24,7 +24,7 @@ public class WkcacheRemoveAllInterceptor extends AbstractWkcacheInterceptor { .getAnnotation(CacheDefaults.class); cacheName = cacheDefaults != null ? cacheDefaults.cacheName() : "wk"; } - for (String s : cacheName.split(",|;")) { + for (String s : cacheName.split(",")) { if (Strings.isNotBlank(s)) { Set set = redisService().keys((s + ":*").getBytes()); for (byte[] it : set) { -- Gitee