Commit 27a8a5c2 by 仲光辉

style: do some style.

parent 612a46be
......@@ -101,7 +101,7 @@ cache: `redis`
return gson.fromJson(cache, new TypeToken<Optional<Provinces>>() {
}.getType());
} else {
// 数据没有缓存
// 数据没有缓存
// TODO 缓存击穿 分布式锁 etc. Redisson 可以参阅 cn.dankal.share.cache.reference
Provinces provinces = this.getProvincesByProvinces(provincesId);
Optional<Provinces> provincesOptional;
......@@ -113,7 +113,7 @@ cache: `redis`
final long timeoutInMinutes = Const.CacheTimeout.TIMEOUT_PROVINCES_DETAIL_MINUTES;
stringRedisTemplate.opsForValue().set(key, gson.toJson(provincesOptional), timeoutInMinutes, TimeUnit.MINUTES);
} else {
// 防止缓存穿透
// 防止缓存穿透
if (log.isDebugEnabled()) {
log.debug("detailWithRedisCache ==> {} preven cache break down .", Thread.currentThread().getName());
}
......@@ -179,7 +179,7 @@ etc.
.builder(connectionFactory)
.cacheDefaults(
RedisCacheConfiguration.defaultCacheConfig()
//缓存时间绝对过期时间20s
//缓存时间绝对过期时间120s
.entryTtl(Duration.ofSeconds(120)))
.transactionAware()
.build();
......
......@@ -48,7 +48,7 @@ public class SpringCacheConfig {
.builder(connectionFactory)
.cacheDefaults(
RedisCacheConfiguration.defaultCacheConfig()
//缓存时间绝对过期时间20s
//缓存时间绝对过期时间120s
.entryTtl(Duration.ofSeconds(120)))
.transactionAware()
.build();
......
......@@ -15,7 +15,6 @@ import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
......@@ -302,7 +301,7 @@ public class RedisCacheAspect {
if (redisCache.dynamicDistributedLockKey()) {
// 动态分布式锁的 key
String dynamicDistributedLockKeyPattern = redisCache.dynamicDistributedLockKeyPattern();
if (StringUtils.isEmpty(dynamicDistributedLockKeyPattern)) {
if (StrUtil.isBlank(dynamicDistributedLockKeyPattern)) {
throw new IllegalArgumentException(
"使用 动态的分布式锁key(dynamicDistributedLockKey=ture),但是未指定 dynamicDistributedLockKeyPattern");
}
......@@ -320,7 +319,7 @@ public class RedisCacheAspect {
} else {
// 直接 指定 分布式锁的 key
distributedLockKey = redisCache.distributedLockKey();
if (StringUtils.isEmpty(distributedLockKey)) {
if (StrUtil.isBlank(distributedLockKey)) {
throw new IllegalStateException(
"未使用 动态的分布式锁key(dynamicDistributedLockKey=false),但是未指定 distributedLockKey");
}
......@@ -374,7 +373,7 @@ public class RedisCacheAspect {
}
// 动态 缓存key
String dynamicCacheKeyPattern = redisCache.dynamicCacheKeyPattern();
if (StringUtils.isEmpty(dynamicCacheKeyPattern)) {
if (StrUtil.isBlank(dynamicCacheKeyPattern)) {
throw new IllegalStateException("使用动态缓存key. 但是尚未配置 动态key pattern(dynamicCacheKeyPattern)");
}
if (!dynamicCacheKeyPattern.contains(HUTOOL_FORMAT_PLACE_HOLDER)) {
......@@ -390,7 +389,7 @@ public class RedisCacheAspect {
} else {
// 使用指定的 cache key
cacheKey = redisCache.cacheKey();
if (StringUtils.isEmpty(cacheKey)) {
if (StrUtil.isBlank(cacheKey)) {
throw new IllegalStateException("未使用动态缓存key,但是亦为指定 cacheKey");
}
}
......@@ -485,7 +484,7 @@ public class RedisCacheAspect {
// 获取数据 redis 的 String数据类型: key,value 都是JSON 字符串
String cache = stringRedisTemplate.opsForValue().get(key);
// 命中缓存
if (!StringUtils.isEmpty(cache)) {
if (StrUtil.isNotBlank(cache)) {
// 有数据 ,则将数据进行转化
return gson.fromJson(cache, TypeUtil.getReturnType(signature.getMethod()));
}
......@@ -501,7 +500,7 @@ public class RedisCacheAspect {
while ((System.currentTimeMillis() - startMs) <= spinTryTimeInSecond * THOUSANDS_OF_ONE) {
String cacheContent = stringRedisTemplate.opsForValue().get(key);
// 命中缓存
if (!StringUtils.isEmpty(cacheContent)) {
if (StrUtil.isNotBlank(cacheContent)) {
if (log.isDebugEnabled()) {
log.debug("{} 调用方法 {} 现在 成功获取到缓存数据", Thread.currentThread().getName(), signature.getName());
}
......
......@@ -139,6 +139,7 @@ public class IProvincesServiceImpl extends ServiceImpl<ProvincesMapper, Province
@CacheEvict(cacheNames = "provinces_detail_cache", key = "#provinces.provinceId")
@Override
public Optional<Integer> updateProvinces(Provinces provinces) {
LambdaQueryWrapper<Provinces> provincesLambdaQueryWrapper = new LambdaQueryWrapper<Provinces>()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment