diff --git a/Milkomeda/pom.xml b/Milkomeda/pom.xml index 62ec2c1d..a71f3de8 100755 --- a/Milkomeda/pom.xml +++ b/Milkomeda/pom.xml @@ -11,7 +11,7 @@ 1.8 - 3.12.3-SNAPSHOT + 3.12.4-SNAPSHOT 2.2.4 Hoxton.RELEASE 2.1.1 @@ -67,7 +67,7 @@ sonatype-oss-release - 3.12.3 + 3.12.4 diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/crust/CrustConfig.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/crust/CrustConfig.java index 96c64ece..5ee3fc5e 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/crust/CrustConfig.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/crust/CrustConfig.java @@ -19,7 +19,7 @@ * * @author yizzuide * @since 1.14.0 - * @version 3.3.0 + * @version 3.12.4 * Create at 2019/11/11 14:56 */ @Configuration @@ -69,6 +69,7 @@ public Cache lightCache() { lightCache.setOnlyCacheL1(!crustProps.isEnableCacheL2()); lightCache.setL2Expire(lightProps.getL2Expire().getSeconds()); lightCache.setOnlyCacheL2(false); + lightCache.setEnableSuperCache(lightProps.isEnableSuperCache()); return lightCache; } } diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/CacheHelper.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/CacheHelper.java index 6618d69b..516dd416 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/CacheHelper.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/CacheHelper.java @@ -14,7 +14,7 @@ * 缓存外层API,集超级缓存、一级缓存、二级缓存于一体的方法 * * @since 1.10.0 - * @version 3.2.1 + * @version 3.12.4 * @author yizzuide * Create at 2019/07/02 11:36 */ @@ -136,7 +136,7 @@ public static E get(Cache cache, TypeReference eTypeRef, Serializable id Spot fastSpot = null; if (cache instanceof LightCache) { LightCache lightCache = (LightCache) cache; - if (!lightCache.getOnlyCacheL2()) { + if (lightCache.isEnableSuperCache() && !lightCache.getOnlyCacheL2()) { // 方案一:从超级缓存中获取,内存指针引用即可返回(耗时为O(1)) fastSpot = get(cache); if (fastSpot != null) { @@ -217,7 +217,7 @@ public static E put(Cache cache, Serializable id, Spot fastSpot = null; if (cache instanceof LightCache) { LightCache lightCache = (LightCache) cache; - if (!lightCache.getOnlyCacheL2()) { + if (lightCache.isEnableSuperCache() && !lightCache.getOnlyCacheL2()) { fastSpot = get(cache); if (fastSpot == null) { // 设置超级缓存 diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCache.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCache.java index 59199684..f7522fb4 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCache.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCache.java @@ -27,7 +27,7 @@ * E:缓存业务数据 * * @since 1.8.0 - * @version 3.7.0 + * @version 3.12.4 * @author yizzuide * Create at 2019/06/28 13:33 */ @@ -92,6 +92,13 @@ public class LightCache implements Cache { @Getter private Boolean onlyCacheL2; + /** + * 开启超缓存 + */ + @Setter + @Getter + private boolean enableSuperCache; + /** * 超级缓存(每个Cache都有自己的超级缓存,互不影响) */ @@ -379,6 +386,7 @@ public void copyFrom(LightCache other) { this.setOnlyCacheL1(other.getOnlyCacheL1()); this.setL2Expire(other.getL2Expire()); this.setOnlyCacheL2(other.getOnlyCacheL2()); + this.setEnableSuperCache(other.isEnableSuperCache()); } /** @@ -394,5 +402,6 @@ public void configFrom(LightProperties props) { this.setOnlyCacheL1(props.isOnlyCacheL1()); this.setL2Expire(props.getL2Expire().getSeconds()); this.setOnlyCacheL2(props.isOnlyCacheL2()); + this.setEnableSuperCache(props.isEnableSuperCache()); } } diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCacheCleanAstrolabeHandler.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCacheCleanAstrolabeHandler.java index d7b1ac5c..22e26a19 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCacheCleanAstrolabeHandler.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightCacheCleanAstrolabeHandler.java @@ -13,7 +13,7 @@ * 超级缓存清理 * * @author yizzuide - * @since 3.3.0 + * @since 3.12.4 * Create at 2020/05/06 14:13 */ public class LightCacheCleanAstrolabeHandler implements AstrolabeHandler { @@ -21,9 +21,11 @@ public class LightCacheCleanAstrolabeHandler implements AstrolabeHandler { @Override public void postHandle(ServletRequest request, ServletResponse response) { // 清除请求线程的所有Cache子实例的超级缓存 - Map cacheMap = ApplicationContextHolder.get().getBeansOfType(Cache.class); - for (Cache cache : cacheMap.values()) { - CacheHelper.remove(cache); + Map cacheMap = ApplicationContextHolder.get().getBeansOfType(LightCache.class); + for (LightCache cache : cacheMap.values()) { + if (cache.isEnableSuperCache()) { + CacheHelper.remove(cache); + } } } diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightProperties.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightProperties.java index 0adfb6d2..09b29ac1 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightProperties.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/light/LightProperties.java @@ -14,7 +14,7 @@ * * @author yizzuide * @since 1.17.0 - * @version 3.0.0 + * @version 3.12.4 * Create at 2019/12/03 16:24 */ @Data @@ -49,4 +49,10 @@ public class LightProperties { * 自定义实例名配置(实例的注册方式为首次使用时) */ private Map instances = new HashMap<>(); + + /** + * 是否开启超缓存 + * @since 3.12.4 + */ + private boolean enableSuperCache = true; } diff --git a/MilkomedaDemo/pom.xml b/MilkomedaDemo/pom.xml index cece4a2b..16b79c42 100644 --- a/MilkomedaDemo/pom.xml +++ b/MilkomedaDemo/pom.xml @@ -20,7 +20,7 @@ UTF-8 1.8 Hoxton.RELEASE - 3.12.3-SNAPSHOT + 3.12.4-SNAPSHOT 2.1.1 3.12.5 3.4.14