diff --git a/dao/src/main/java/org/thingsboard/server/dao/resource/DefaultTbResourceDataCache.java b/dao/src/main/java/org/thingsboard/server/dao/resource/DefaultTbResourceDataCache.java index 343c37299e..925b8c2912 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/resource/DefaultTbResourceDataCache.java +++ b/dao/src/main/java/org/thingsboard/server/dao/resource/DefaultTbResourceDataCache.java @@ -19,6 +19,7 @@ import com.github.benmanes.caffeine.cache.AsyncLoadingCache; import com.github.benmanes.caffeine.cache.Caffeine; import com.google.common.util.concurrent.FluentFuture; import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -55,6 +56,12 @@ public class DefaultTbResourceDataCache implements TbResourceDataCache { .buildAsync((key, executor) -> CompletableFuture.supplyAsync(() -> resourceService.getResourceDataInfo(key.tenantId(), key.resourceId()), executor)); } + @PreDestroy + private void destroy() { + cache.synchronous().invalidateAll(); + cache = null; + } + @Override public FluentFuture getResourceDataInfoAsync(TenantId tenantId, TbResourceId resourceId) { log.trace("Retrieving resource data info by id [{}], tenant id [{}] from cache", resourceId, tenantId);