提交 84e4bfbc 编写于 作者: 智布道's avatar 智布道 👁

💩 增加 enableRedisCache 参数,可以动态开启 redis 切面缓存,开发环境可以关闭该配置,方便调试

上级 f696b9dc
...@@ -2,6 +2,7 @@ package com.zyd.blog.business.aspect; ...@@ -2,6 +2,7 @@ package com.zyd.blog.business.aspect;
import com.zyd.blog.business.annotation.RedisCache; import com.zyd.blog.business.annotation.RedisCache;
import com.zyd.blog.business.service.RedisService; import com.zyd.blog.business.service.RedisService;
import com.zyd.blog.framework.property.AppProperties;
import com.zyd.blog.util.AspectUtil; import com.zyd.blog.util.AspectUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
...@@ -31,6 +32,8 @@ public class RedisCacheAspect { ...@@ -31,6 +32,8 @@ public class RedisCacheAspect {
@Autowired @Autowired
private RedisService redisService; private RedisService redisService;
@Autowired
private AppProperties appProperties;
@Pointcut(value = "@annotation(com.zyd.blog.business.annotation.RedisCache)") @Pointcut(value = "@annotation(com.zyd.blog.business.annotation.RedisCache)")
public void pointcut() { public void pointcut() {
...@@ -38,6 +41,9 @@ public class RedisCacheAspect { ...@@ -38,6 +41,9 @@ public class RedisCacheAspect {
@Around("pointcut()") @Around("pointcut()")
public Object handle(ProceedingJoinPoint point) throws Throwable { public Object handle(ProceedingJoinPoint point) throws Throwable {
if (!appProperties.isEnableRedisCache()) {
return point.proceed();
}
Method currentMethod = AspectUtil.INSTANCE.getMethod(point); Method currentMethod = AspectUtil.INSTANCE.getMethod(point);
//获取操作名称 //获取操作名称
RedisCache cache = currentMethod.getAnnotation(RedisCache.class); RedisCache cache = currentMethod.getAnnotation(RedisCache.class);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册