Redis快取切面,防止Redis當機影響正常業務邏輯
標題很清楚了,不說了
package com.raymon.hcp.security.aspect;
import com.raymon.hcp.security.annotation.CacheException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* Redis快取切面,防止Redis當機影響正常業務邏輯
* Created by zhanglei on 2020/3/17.
*/
@Aspect
@Component
@Order(2)
public class RedisCacheAspect {
private static Logger LOGGER = LoggerFactory.getLogger(RedisCacheAspect.class);
@Pointcut("execution(public * com.raymon.hcp.portal.service.*CacheService.*(..)) || execution(public * com.raymon.hcp.service.*CacheService.*(..))")
public void cacheAspect() {
}
@Around("cacheAspect()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
Object result = null;
try {
result = joinPoint.proceed();
} catch (Throwable throwable) {
//有CacheException註解的方法需要丟擲異常
if (method.isAnnotationPresent(CacheException.class)) {
throw throwable;
} else {
LOGGER.error(throwable.getMessage());
}
}
return result;
}
}
相關文章
- redis快取和業務應用瞭解Redis快取
- 【Azure Redis 快取】Azure Redis 服務不支援指令CONFIGRedis快取
- Redis快取穿透Redis快取穿透
- Redis 的快取淘汰機制(Eviction)Redis快取
- Redis快取穿透、快取雪崩、redis併發問題分析Redis快取穿透
- 【Azure Redis 快取 Azure Cache For Redis】Redis連線池Redis快取
- redis實現文章投票邏輯Redis
- 【Azure Redis 快取】如何得知Azure Redis服務有更新行為?Redis快取
- Redis快取擊穿、快取穿透、快取雪崩Redis快取穿透
- [Redis]快取穿透/快取擊穿/快取雪崩Redis快取穿透
- SpringBoot整合Redis快取Spring BootRedis快取
- redis→分散式快取Redis分散式快取
- redis快取介紹Redis快取
- 如何使用 Redis 快取Redis快取
- Laravel使用Redis快取LaravelRedis快取
- (四)Redis 快取應用、淘汰機制Redis快取
- Redis快取篇(四)快取異常Redis快取
- Redis快取篇(一)Redis是如何工作的Redis快取
- SpringBoot快取管理(三) 自定義Redis快取序列化機制Spring Boot快取Redis
- SmartSql Redis 分散式快取SQLRedis分散式快取
- Spring Boot Cache Redis快取Spring BootRedis快取
- redis快取優化案例Redis快取優化
- springboot +lettuce +redis 快取使用Spring BootRedis快取
- redis 快取 singlefly 查詢Redis快取
- Redis快取穿透和雪崩Redis快取穿透
- Redis快取穿透與雪崩Redis快取穿透
- 3.2.2的Model的快取邏輯快取
- unbound中快取時間邏輯快取
- Redis當機恢復Redis
- redis13_redis快取相關問題5Redis快取
- 【Azure Redis 快取】Azure Redis功能性討論Redis快取
- Redis詳解(十二)------ 快取穿透、快取擊穿、快取雪崩Redis快取穿透
- 什麼是redis快取雪崩、快取穿透、快取擊穿Redis快取穿透
- Redis——快取穿透、快取擊穿、快取雪崩、分散式鎖Redis快取穿透分散式
- Redis快取穿透、快取雪崩、快取擊穿好好說說Redis快取穿透
- SpringBoot快取管理(二) 整合Redis快取實現Spring Boot快取Redis
- SpringBoot 註解呼叫Redis快取Spring BootRedis快取
- SpringBoot中整合Redis(快取篇)Spring BootRedis快取