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.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier.java

@Inject
protected RegionAndNameToImageSupplier(CacheLoader<RegionAndName, Image> regionAndIdToImage,
        @Named(PROPERTY_SESSION_INTERVAL) long expirationSecs) {
    cache = CacheBuilder.newBuilder().expireAfterWrite(expirationSecs, TimeUnit.SECONDS)
            .build(regionAndIdToImage);/*from   w w w  .j  a  v  a2  s.c o m*/
}

From source file:umich.ms.batmass.data.core.api.DataContainer.java

public DataContainer(DataSource<T> source) {
    this.source = source;
    this.cacheRemovalListener = buildRemovalListener();
    this.cache = CacheBuilder.newBuilder().weakKeys().concurrencyLevel(1).removalListener(cacheRemovalListener)
            .build();/*ww w  .j a va  2s. com*/
}

From source file:org.erlide.common.util.TermParser.java

private TermParser() {
    cache = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.HOURS).maximumSize(250)
            .build(new CacheLoader<String, OtpErlangObject>() {
                @Override//  w ww .  jav a2s.c o m
                public OtpErlangObject load(final String key) throws TermParserException {
                    return parse(scan(key));
                }
            });
}

From source file:springfox.documentation.schema.CachingModelDependencyProvider.java

@Autowired
public CachingModelDependencyProvider(@Qualifier("default") final ModelDependencyProvider delegate) {
    cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(24, TimeUnit.HOURS)
            .build(new CacheLoader<ModelContext, Set<ResolvedType>>() {
                public Set<ResolvedType> load(ModelContext key) {
                    return delegate.dependentModels(key);
                }//w  w w  .  j a v  a2 s  .c  om
            });
}

From source file:com.codebullets.sagalib.processing.SagaInstanceCreator.java

/**
 * Generates a new instance of ProviderCache.
 *///from   w ww. java 2s .  c o  m
@Inject
public SagaInstanceCreator(final SagaProviderFactory providerFactory, final TimeoutManager timeoutManager) {
    this.timeoutManager = timeoutManager;
    // Create providers when needed. Cache providers for later use.
    providers = CacheBuilder.newBuilder().build(new ProviderLoader(providerFactory));
}

From source file:org.apache.usergrid.corepersistence.index.CollectionSettingsFactory.java

@Inject
public CollectionSettingsFactory(final CollectionSettingsCacheFig fig,
        final MapManagerFactory mapManagerFactory, final CollectionSettingsCache collectionSettingsCache) {

    indexSchemaCache = CacheBuilder.newBuilder().maximumSize(fig.getCacheSize())
            .expireAfterWrite(fig.getCacheTimeout(), TimeUnit.MILLISECONDS)
            .build(new CacheLoader<CollectionSettingsScope, CollectionSettings>() {
                @Override/*  w w  w  . j  av  a  2 s  .c  om*/
                public CollectionSettings load(CollectionSettingsScope scope) throws Exception {

                    final MapManager mm = mapManagerFactory
                            .createMapManager(CpNamingUtils.getEntityTypeMapScope(scope.getApplication()));
                    return new CollectionSettingsImpl(scope, mm, collectionSettingsCache);
                }
            });
}

From source file:net.dmulloy2.swornrpg.modules.RareDrops.java

@Override
public void loadSettings() {
    setEnabled(plugin.getConfig().getBoolean("blockDropsEnabled", true));
    if (plugin.getConfig().getBoolean("trackBlockDrops", false))
        tracked = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();

}

From source file:org.gradle.plugins.ide.idea.model.internal.PathInterner.java

public PathInterner(int cacheMaxSize) {
    filePathCache = CacheBuilder.newBuilder().maximumSize(cacheMaxSize).build();
    pathCache = CacheBuilder.newBuilder().maximumSize(cacheMaxSize).build();
}

From source file:org.jclouds.byon.config.CacheNodeStoreModule.java

public CacheNodeStoreModule(Map<String, Node> backing) {
    this(CacheBuilder.newBuilder().<String, Node>build(CacheLoader.from(Functions.forMap(backing))));
    for (String node : backing.keySet())
        this.backing.getUnchecked(node);
}

From source file:com.addthis.hydra.job.store.CachedSpawnDataStore.java

public CachedSpawnDataStore(SpawnDataStore dataStore, long dataStoreCacheSize) {
    this.dataStore = dataStore;
    this.cache = CacheBuilder.newBuilder().weigher(new Weigher<Pair<String, String>, String>() {
        @Override/*from   www . j  av a  2s . com*/
        public int weigh(Pair<String, String> key, String value) {
            int leftWeight = key.getLeft() != null ? key.getLeft().length() : 0;

            int rightWeight = key.getRight() != null ? key.getRight().length() : 0;

            // Multiply strlen by 2 (full width characters in java
            return 2 * (value.length() + leftWeight + rightWeight);
        }
    }).maximumWeight(dataStoreCacheSize).build(new CacheLoader<Pair<String, String>, String>() {
        @Override
        public String load(Pair<String, String> key) throws Exception {
            String path = key.getLeft();
            String childId = key.getRight();

            if (childId == null) {
                return CachedSpawnDataStore.this.dataStore.get(path);
            } else {
                return CachedSpawnDataStore.this.dataStore.getChild(path, childId);
            }
        }
    });
}