9 Haziran 2019 Pazar

SpringCache GuavaCacheManager Sınıfı - Kullanmayın

Giriş
Guava desteği artık yok. Caffeine kullanmak gerekiyor.
Şöyle yaparız
// From:
GuavaCacheManager guavaCacheManager = new GuavaCacheManager();
guavaCacheManager.setCacheBuilder(CacheBuilder.newBuilder()
  .expireAfterWrite(1, CACHE_TIME_UNIT));

// To:
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
cacheManager.setCaffeine(Caffeine.newBuilder()
  .expireAfterWrite(1, CACHE_TIME_UNIT));
constructor
Örnek
Şöyle yaparız.
@Bean
public CacheManager cacheManager() {
  GuavaCacheManager guavaCacheManager = new GuavaCacheManager();
  guavaCacheManager.setCacheBuilder(CacheBuilder.newBuilder()
    .expireAfterWrite(10, TimeUnit.MINUTES));
  return guavaCacheManager;
}
constructor - String
Örnek
Şöyle yaparız.
@Bean
public CacheManager cacheManager() {
  return new GuavaCacheManager("CustomerCache");
}
Örnek
Şöyle yaparız.
@Bean
public CacheManager cacheManager() {
  GuavaCacheManager cacheManager = new GuavaCacheManager("ceepCache");
  CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder().maximumSize(100)
    .expireAfterWrite(10,TimeUnit.MINUTES);
  cacheManager.setCacheBuilder(cacheBuilder);
  return cacheManager;
}

Hiç yorum yok:

Yorum Gönder