use of com.hccake.ballcat.common.redis.core.annotation.CacheDel in project ballcat by ballcat-projects.
the class CacheStringAspect method around.
@Around("pointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
// 获取目标方法
MethodSignature signature = (MethodSignature) point.getSignature();
Method method = signature.getMethod();
log.trace("=======The string cache aop is executed! method : {}", method.getName());
// 根据方法的参数 以及当前类对象获得 keyGenerator
Object target = point.getTarget();
Object[] arguments = point.getArgs();
KeyGenerator keyGenerator = new KeyGenerator(target, method, arguments);
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
// 获取注解对象
Cached cachedAnnotation = AnnotationUtils.getAnnotation(method, Cached.class);
if (cachedAnnotation != null) {
// 缓存key
String key = keyGenerator.getKey(cachedAnnotation.key(), cachedAnnotation.keyJoint());
// redis 分布式锁的 key
String lockKey = key + CachePropertiesHolder.lockKeySuffix();
Supplier<String> cacheQuery = () -> valueOperations.get(key);
// 失效时间控制
Consumer<Object> cachePut = prodCachePutFunction(valueOperations, key, cachedAnnotation.ttl());
return cached(new CachedOps(point, lockKey, cacheQuery, cachePut, method.getGenericReturnType()));
}
CachePut cachePutAnnotation = AnnotationUtils.getAnnotation(method, CachePut.class);
if (cachePutAnnotation != null) {
// 缓存key
String key = keyGenerator.getKey(cachePutAnnotation.key(), cachePutAnnotation.keyJoint());
// 失效时间控制
Consumer<Object> cachePut = prodCachePutFunction(valueOperations, key, cachePutAnnotation.ttl());
return cachePut(new CachePutOps(point, cachePut));
}
CacheDel cacheDelAnnotation = AnnotationUtils.getAnnotation(method, CacheDel.class);
if (cacheDelAnnotation != null) {
VoidMethod cacheDel;
if (cacheDelAnnotation.multiDel()) {
Collection<String> keys = keyGenerator.getKeys(cacheDelAnnotation.key(), cacheDelAnnotation.keyJoint());
cacheDel = () -> redisTemplate.delete(keys);
} else {
// 缓存key
String key = keyGenerator.getKey(cacheDelAnnotation.key(), cacheDelAnnotation.keyJoint());
cacheDel = () -> redisTemplate.delete(key);
}
return cacheDel(new CacheDelOps(point, cacheDel));
}
return point.proceed();
}
use of com.hccake.ballcat.common.redis.core.annotation.CacheDel in project ballcat by ballcat-projects.
the class I18nDataServiceImpl method saveOrUpdate.
@Override
@CacheDel(key = I18nRedisKeyConstants.I18N_DATA_PREFIX, multiDel = true, keyJoint = "#p0.![#this.code + ':' + #this.languageTag]")
public void saveOrUpdate(List<I18nData> list) {
// 查询已存在的数据
List<I18nData> existsI18nData = baseMapper.exists(list);
HashSet<I18nData> existsSet = new HashSet<>(existsI18nData);
// 获取对应插入和更新的列表
List<I18nDataDTO> updateList = new ArrayList<>();
List<I18nData> insertList = new ArrayList<>();
for (I18nData i18nData : list) {
if (existsSet.contains(i18nData)) {
updateList.add(I18nDataConverter.INSTANCE.poToDto(i18nData));
} else {
insertList.add(i18nData);
}
}
// 小范围事务处理,另外不影响缓存更新
i18NDataTxSupport.saveAndUpdate(insertList, updateList);
// 缓存更新
for (I18nDataDTO i18nDataDTO : updateList) {
String code = i18nDataDTO.getCode();
String languageTag = i18nDataDTO.getLanguageTag();
this.pushUpdateMessage(code, languageTag);
}
}
Aggregations