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()); + } + } + } +}