Giriş
Şu satırı dahil ederiz
import com.github.benmanes.caffeine.cache.Cache;
put metodu
Örnek
Şöyle yaparız
Cache<String, String> cache = Caffeine.newBuilder().build(); cache.put("key", "value"); cache.getIfPresent("key");
stats metodu
Örnek
Şöyle yaparız
Cache<String, String> cache = Caffeine.newBuilder() .recordStats() // Enabled statistics collection .build(); // Add to the cache cache.put("1", "value_1"); cache.put("2", "value_2"); // Simulate hit and miss from cache cache.getIfPresent("1"); cache.getIfPresent("3"); System.out.println(cache.stats());
Çıktı şöyle
"CacheStats"{ hitCount=1, missCount=1, loadSuccessCount=0, loadFailureCount=0, totalLoadTime=0, evictionCount=0, evictionWeight=0 }