Skip to content

Commit d822268

Browse files
author
pig666
committed
🔖 Releasing / Version tags. 0.0.3
1 parent eb6dacf commit d822268

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<dependency>
3333
<groupId>com.pig4cloud.plugin</groupId>
3434
<artifactId>multilevel-cache-spring-boot-starter</artifactId>
35-
<version>0.0.1</version>
35+
<version>0.0.3</version>
3636
</dependency>
3737
```
3838

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.pig4cloud.plugin</groupId>
1212
<artifactId>multilevel-cache-spring-boot-starter</artifactId>
13-
<version>0.0.2</version>
13+
<version>0.0.3</version>
1414
<name>multilevel-cache-spring-boot-starter</name>
1515
<description>support L1 caffeine and L2 redis cache</description>
1616
<url>https://pig4cloud.com</url>

src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.extern.slf4j.Slf4j;
77
import org.springframework.cache.support.AbstractValueAdaptingCache;
88
import org.springframework.data.redis.core.RedisTemplate;
9+
import org.springframework.util.CollectionUtils;
910
import org.springframework.util.StringUtils;
1011

1112
import java.util.Map;
@@ -64,12 +65,11 @@ public <T> T get(Object key, Callable<T> valueLoader) {
6465
return (T) value;
6566
}
6667

67-
ReentrantLock lock = keyLockMap.get(key.toString());
68-
if (lock == null) {
69-
log.debug("create lock for key : {}", key);
70-
lock = new ReentrantLock();
71-
keyLockMap.putIfAbsent(key.toString(), lock);
72-
}
68+
ReentrantLock lock = keyLockMap.computeIfAbsent(key.toString(), s -> {
69+
log.trace("create lock for key : {}", s);
70+
return new ReentrantLock();
71+
});
72+
7373
try {
7474
lock.lock();
7575
value = lookup(key);
@@ -147,8 +147,9 @@ public void evict(Object key) {
147147
public void clear() {
148148
// 先清除redis中缓存数据,然后清除caffeine中的缓存,避免短时间内如果先清除caffeine缓存后其他请求会再从redis里加载到caffeine中
149149
Set<Object> keys = stringKeyRedisTemplate.keys(this.name.concat(":*"));
150-
for (Object key : keys) {
151-
stringKeyRedisTemplate.delete(key);
150+
151+
if (!CollectionUtils.isEmpty(keys)){
152+
stringKeyRedisTemplate.delete(keys);
152153
}
153154

154155
push(new CacheMessage(this.name, null));
@@ -180,9 +181,8 @@ private Object getKey(Object key) {
180181
}
181182

182183
private long getExpire() {
183-
long expire = defaultExpiration;
184184
Long cacheNameExpire = expires.get(this.name);
185-
return cacheNameExpire == null ? expire : cacheNameExpire.longValue();
185+
return cacheNameExpire == null ? defaultExpiration : cacheNameExpire;
186186
}
187187

188188
/**

0 commit comments

Comments
 (0)