Skip to content

Commit

Permalink
feat: CacheStatsLogger ์ถ”๊ฐ€
Browse files Browse the repository at this point in the history
- ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ข…๋ฃŒ ์‹œ์ ์— ์บ์‹œ ์Šคํƒฏ ๋กœ๊น…
  • Loading branch information
seokjin8678 committed Apr 16, 2024
1 parent 115c9eb commit 218aad3
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
}

0 comments on commit 218aad3

Please sign in to comment.