Example usage for com.google.common.cache CacheBuilder newBuilder

List of usage examples for com.google.common.cache CacheBuilder newBuilder

Introduction

In this page you can find the example usage for com.google.common.cache CacheBuilder newBuilder.

Prototype

public static CacheBuilder<Object, Object> newBuilder() 

Source Link

Document

Constructs a new CacheBuilder instance with default settings, including strong keys, strong values, and no automatic eviction of any kind.

Usage

From source file:org.jevis.rest.IconCache.java

/**
 * Default constructor TODO: make the expire date configurable
 *///from www  . j av  a2 s  .  c om
public IconCache() {
    _cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(24, TimeUnit.HOURS)
            .removalListener(new RemovalListener<String, ClassIcon>() {

                @Override
                public void onRemoval(RemovalNotification<String, ClassIcon> notification) {
                    //                        System.out.println("Remove cached icon for: " + notification.getKey() + " because: " + notification.getCause());
                }
            }).build(new CacheLoader<String, ClassIcon>() {

                @Override
                public ClassIcon load(String key) throws Exception {
                    return new ClassIcon(key, null);
                }
            });
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.AppEntityDBLoadingEntityCache.java

public AppEntityDBLoadingEntityCache(int size, CacheLoader<String, AppEntity> appEntityCacheLoader) {
    cache = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(appEntityCacheLoader);
}

From source file:org.onosproject.store.primitives.impl.CachingAsyncLeaderElector.java

public CachingAsyncLeaderElector(AsyncLeaderElector delegateLeaderElector) {
    super(delegateLeaderElector);
    cache = CacheBuilder.newBuilder().maximumSize(1000).build(CacheLoader.from(super::getLeadership));

    cacheUpdater = change -> {//from   www  .  j  a  va 2 s.  com
        Leadership leadership = change.newValue();
        cache.put(leadership.topic(), CompletableFuture.completedFuture(leadership));
    };
    statusListener = status -> {
        if (status == Status.SUSPENDED || status == Status.INACTIVE) {
            cache.invalidateAll();
        }
    };
    addChangeListener(cacheUpdater);
    addStatusChangeListener(statusListener);
}

From source file:org.cloudfoundry.identity.uaa.provider.saml.FixedHttpMetaDataProvider.java

protected static Cache<String, CacheEntry> buildCache() {
    return CacheBuilder.newBuilder().expireAfterWrite(expirationTimeMillis.get(), TimeUnit.MILLISECONDS)
            .maximumSize(20000).ticker(ticker).build();
}

From source file:org.eclipse.kapua.commons.cache.LocalCache.java

/**
 * /*from w w w.j a  v  a2 s  . c om*/
 * @param sizeMax max cache size
 * @param expireAfter values ttl
 * @param defaultValue default value (if no value is found for a specific key)
 */
public LocalCache(int sizeMax, int expireAfter, final V defaultValue) {
    this.defaultValue = defaultValue;
    cache = CacheBuilder.newBuilder().maximumSize(sizeMax).expireAfterWrite(expireAfter, TimeUnit.SECONDS)
            .build();
}

From source file:com.isotrol.impe3.oi.impl.AbstractMapComponent.java

/** Default constructor. */
public AbstractMapComponent() {
    final CacheLoader<K, Long> computer = new CacheLoader<K, Long>() {
        public Long load(K from) {
            return compute(from);
        }// w w  w.j a v  a  2 s  . c o  m
    };
    cache = CacheBuilder.newBuilder().softValues().build(computer);
}

From source file:com.github.jcustenborder.kafka.connect.utils.data.type.DecimalTypeParser.java

public DecimalTypeParser() {
    this.schemaCache = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.SECONDS).build();
}

From source file:com.infinitechaos.vpcviewer.config.CachingConfiguration.java

@Bean
public CacheManager cacheManager() {
    GuavaCacheManager cm = new GuavaCacheManager(VPC_LISTS_CACHE, VPC_CACHE, ROUTE_TABLE_CACHE, SUBNET_CACHE);
    cm.setAllowNullValues(false);/*from  www.ja  va 2 s. co m*/
    cm.setCacheBuilder(CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES));

    return cm;
}

From source file:io.cfp.config.CacheConfig.java

@Bean
public CacheManager cacheManager() {
    // configure and return an implementation of Spring's CacheManager SPI
    SimpleCacheManager cacheManager = new SimpleCacheManager();

    Cache<Object, Object> applicationSettings = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS)
            .build();// w w w  . j ava  2s.  c om

    Cache<Object, Object> isCfpOpen = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build();

    cacheManager.setCaches(Arrays.asList(new GuavaCache("applicationSettings", applicationSettings),
            new GuavaCache("isCfpOpen", isCfpOpen)));

    return cacheManager;
}

From source file:com.hortonworks.registries.schemaregistry.client.SchemaMetadataCache.java

public SchemaMetadataCache(Long size, Long expiryInSecs, final SchemaMetadataFetcher schemaMetadataFetcher) {
    loadingCache = CacheBuilder.newBuilder().maximumSize(size).expireAfterAccess(expiryInSecs, TimeUnit.SECONDS)
            .build(new CacheLoader<Key, SchemaMetadataInfo>() {
                @Override/* w  w w.j  a v  a2 s .  co  m*/
                public SchemaMetadataInfo load(Key key) throws Exception {
                    if (key.getName() != null) {
                        return schemaMetadataFetcher.fetch(key.getName());
                    } else if (key.getId() != null) {
                        return schemaMetadataFetcher.fetch(key.getId());
                    } else {
                        throw new IllegalArgumentException("Key should have name or id as non null");
                    }
                }
            });
}