Java Code Examples for org.springframework.cache.caffeine.CaffeineCacheManager#setCaffeine()

The following examples show how to use org.springframework.cache.caffeine.CaffeineCacheManager#setCaffeine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAdapterConfig.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create a new cache provider based on Caffeine and Spring Cache.
 *
 * @param minCacheSize The minimum size of the cache.
 * @param maxCacheSize the maximum size of the cache.
 * @return A new cache provider or {@code null} if no cache should be used.
 */
private static CacheProvider newCaffeineCache(final int minCacheSize, final long maxCacheSize) {

    if (maxCacheSize <= 0) {
        return null;
    }

    final Caffeine<Object, Object> caffeine = Caffeine.newBuilder()
            .initialCapacity(minCacheSize)
            .maximumSize(Math.max(minCacheSize, maxCacheSize));

    final CaffeineCacheManager manager = new CaffeineCacheManager();
    manager.setAllowNullValues(false);
    manager.setCaffeine(caffeine);

    return new SpringCacheProvider(manager);
}
 
Example 2
Source File: RolloutStatusCache.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param tenantAware
 *            to get current tenant
 * @param size
 *            the maximum size of the cache
 */
public RolloutStatusCache(final TenantAware tenantAware, final long size) {
    this.tenantAware = tenantAware;

    final Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder().maximumSize(size);
    final CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
    caffeineCacheManager.setCaffeine(cacheBuilder);

    this.cacheManager = new TenantAwareCacheManager(caffeineCacheManager, tenantAware);
}
 
Example 3
Source File: CacheAutoConfiguration.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the direct cache manager to access without tenant aware
 *         check, cause in sometimes it's necessary to access the cache
 *         directly without having the current tenant, e.g. initial
 *         creation of tenant
 */
@Bean(name = "directCacheManager")
@ConditionalOnMissingBean(name = "directCacheManager")
public CacheManager directCacheManager(final CacheProperties cacheProperties) {
    final CaffeineCacheManager cacheManager = new CaffeineCacheManager();

    if (cacheProperties.getTtl() > 0) {
        final Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
                .expireAfterWrite(cacheProperties.getTtl(), cacheProperties.getTtlUnit());
        cacheManager.setCaffeine(cacheBuilder);
    }

    return cacheManager;
}
 
Example 4
Source File: UtilConfiguration.java    From kaif with Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager rssHotArticlesCacheManager() {
  Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
      .expireAfterWrite(4, TimeUnit.HOURS)
      .maximumSize(100);
  CaffeineCacheManager cacheManager = new CaffeineCacheManager("rssHotArticles");
  cacheManager.setCaffeine(cacheBuilder);
  return cacheManager;
}
 
Example 5
Source File: UtilConfiguration.java    From kaif with Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager zoneInfoCacheManager() {
  Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
      .expireAfterWrite(10, TimeUnit.MINUTES)
      .maximumSize(2000);
  CaffeineCacheManager cacheManager = new CaffeineCacheManager("ZoneInfo");
  cacheManager.setCaffeine(cacheBuilder);
  return cacheManager;
}
 
Example 6
Source File: UtilConfiguration.java    From kaif with Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager articleCacheManager() {
  Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
      .expireAfterWrite(10, TimeUnit.MINUTES)
      .maximumSize(2000);
  CaffeineCacheManager cacheManager = new CaffeineCacheManager("Article");
  cacheManager.setCaffeine(cacheBuilder);
  return cacheManager;
}
 
Example 7
Source File: UtilConfiguration.java    From kaif with Apache License 2.0 5 votes vote down vote up
/**
 * hot zones cache, refresh every one hour. no need to distribute if we have multiple web servers
 *
 * @see {@link io.kaif.model.article.ArticleDao#listHotZonesWithCache(int, java.time.Instant)}
 */
@Bean
public CacheManager listHotZonesCacheManager() {
  Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
      .expireAfterWrite(1, TimeUnit.HOURS)
      .maximumSize(1000);
  CaffeineCacheManager cacheManager = new CaffeineCacheManager("listHotZones");
  cacheManager.setCaffeine(cacheBuilder);
  return cacheManager;
}
 
Example 8
Source File: UtilConfiguration.java    From kaif with Apache License 2.0 5 votes vote down vote up
/**
 * administrators cache, refresh every one minutes. no need to distribute if we have multiple
 * web servers (user just not see new administrators)
 */
@Bean
public CacheManager listAdministratorsCacheManager() {
  Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
      .expireAfterWrite(1, TimeUnit.MINUTES)
      .maximumSize(1000);
  CaffeineCacheManager cacheManager = new CaffeineCacheManager("listAdministrators");
  cacheManager.setCaffeine(cacheBuilder);
  return cacheManager;
}
 
Example 9
Source File: UtilConfiguration.java    From kaif with Apache License 2.0 5 votes vote down vote up
/**
 * short life client app user cache (the cache is Optional<ClientAppUser>), so this is not
 * distribute-able
 *
 * @see {@link io.kaif.model.clientapp.ClientAppDao#findClientAppUserWithCache}
 */
@Bean
public CacheManager findClientAppUserCacheManager() {
  Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
      .expireAfterWrite(1, TimeUnit.MINUTES)
      .maximumSize(1000);
  CaffeineCacheManager cacheManager = new CaffeineCacheManager("findClientAppUser");
  cacheManager.setCaffeine(cacheBuilder);
  return cacheManager;
}
 
Example 10
Source File: UtilConfiguration.java    From kaif with Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager honorRollsCacheManager() {
  Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
      .expireAfterWrite(1, TimeUnit.HOURS)
      .maximumSize(100);
  CaffeineCacheManager cacheManager = new CaffeineCacheManager("listHonorRoll");
  cacheManager.setCaffeine(cacheBuilder);
  return cacheManager;
}
 
Example 11
Source File: CaffeineConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public CacheManager cacheManager(Caffeine caffeine) {
    CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
    caffeineCacheManager.getCache("addresses");
    caffeineCacheManager.setCaffeine(caffeine);
    return caffeineCacheManager;
}