From cb6526c845d75347989c17dbf4420b82a22005b3 Mon Sep 17 00:00:00 2001 From: Karson <31433550+karsonto@users.noreply.github.com> Date: Fri, 14 Jan 2022 15:52:16 +0800 Subject: [PATCH] [ISSUE #7837] add expire checking for AutoExpireCache in common util. (#7392) --- .../common/cache/decorators/AutoExpireCache.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/alibaba/nacos/common/cache/decorators/AutoExpireCache.java b/common/src/main/java/com/alibaba/nacos/common/cache/decorators/AutoExpireCache.java index c793ef170..c8884c872 100644 --- a/common/src/main/java/com/alibaba/nacos/common/cache/decorators/AutoExpireCache.java +++ b/common/src/main/java/com/alibaba/nacos/common/cache/decorators/AutoExpireCache.java @@ -55,10 +55,18 @@ public class AutoExpireCache implements Cache { } return this.delegate.get(key); } - + @Override public V get(K key, Callable call) throws Exception { - return this.delegate.get(key, call); + V cachedValue = this.get(key); + if (null == cachedValue) { + V v2 = call.call(); + this.put(key, v2); + return v2; + + } + return cachedValue; + } @Override