1 Mart 2020 Pazar

Caffeine LoadingCache Arayüzü

Giriş
Şu satırı dahil ederiz
import com.github.benmanes.caffeine.cache.LoadingCache;
constructor 
Örnek
Şöyle yaparız.
LoadingCache<String, Graph> graphs = Caffeine.newBuilder()
  .maximumSize(10_000)
  .refreshAfterWrite(1, TimeUnit.MINUTES)
  .build(key -> getGraphFromDB.apply(key));
Örnek
Şöyle yaparız
LoadingCache<String, String> cache = Caffeine.newBuilder()
  .build(key -> {
    System.out.println("Fetching value for key: " + key);
    return String.format("value_%s", key);
});

// Calculate value and add it to the cache
System.out.println(cache.get("1"));

// Read from cache
System.out.println(cache.get("1"));


Hiç yorum yok:

Yorum Gönder