From 218aad392373d16ef679e92f49fd51e0a8c33bb6 Mon Sep 17 00:00:00 2001 From: seokjin8678 Date: Wed, 17 Apr 2024 02:54:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20CacheStatsLogger=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 어플리케이션 종료 시점에 캐시 스탯 로깅 --- .../common/cache/CacheStatsLogger.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 backend/src/main/java/com/festago/common/cache/CacheStatsLogger.java diff --git a/backend/src/main/java/com/festago/common/cache/CacheStatsLogger.java b/backend/src/main/java/com/festago/common/cache/CacheStatsLogger.java new file mode 100644 index 000000000..215bbe8b8 --- /dev/null +++ b/backend/src/main/java/com/festago/common/cache/CacheStatsLogger.java @@ -0,0 +1,28 @@ +package com.festago.common.cache; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.caffeine.CaffeineCache; +import org.springframework.context.event.ContextClosedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class CacheStatsLogger { + + private final CacheManager cacheManager; + + @EventListener(ContextClosedEvent.class) + public void logCacheStats() { + for (String cacheName : cacheManager.getCacheNames()) { + Cache cache = cacheManager.getCache(cacheName); + if (cache instanceof CaffeineCache caffeineCache) { + log.info("CacheName={} CacheStats={}", cacheName, caffeineCache.getNativeCache().stats()); + } + } + } +}