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

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

Introduction

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

Prototype

public <K1 extends K, V1 extends V> LoadingCache<K1, V1> build(CacheLoader<? super K1, V1> loader) 

Source Link

Document

Builds a cache, which either returns an already-loaded value for a given key or atomically computes or retrieves it using the supplied CacheLoader .

Usage

From source file:org.javersion.store.jdbc.GuavaGraphCache.java

@SuppressWarnings("unchecked")
public GuavaGraphCache(VersionStore<Id, M> versionStore, CacheBuilder<Object, Object> cacheBuilder,
        GraphOptions<Id, M> graphOptions) {
    this.cache = cacheBuilder.build(newCacheLoader(versionStore));
    this.cachedDocIds = cache.asMap().keySet();
    this.graphOptions = firstNonNull(graphOptions, DEFAULT_CACHE_OPTIONS);
}

From source file:com.rhythm.louie.cache.GuavaLoadingCache.java

private GuavaLoadingCache(String name, CacheBuilder<K, V> bldr, CacheLoader<K, V> loader) {
    this.cacheName = name;
    this.cache = bldr.build(loader);
}

From source file:com.google.gitiles.blame.BlameCacheImpl.java

public BlameCacheImpl(CacheBuilder<? super Key, ? super List<Region>> builder) {
    this.cache = builder.build(new CacheLoader<Key, List<Region>>() {
        @Override//from  www  .j av  a  2  s.  c  o  m
        public List<Region> load(Key key) throws IOException {
            return loadBlame(key);
        }
    });
}

From source file:io.soliton.shapeshifter.SchemaRegistry.java

/**
 * Constructs a new instance of this class with the given caching policy.
 *
 * @param cacheBuilder a configured {@link CacheBuilder} for storing
 *                     instances of automatically generated schema
 *///from w  w w. j  a  v  a 2 s. c om
public SchemaRegistry(CacheBuilder<Object, Object> cacheBuilder) {
    Preconditions.checkNotNull(cacheBuilder);
    this.schemas = new MapMaker().makeMap();
    this.autoSchemas = cacheBuilder.build(AUTO_SCHEMA_LOADER);
}

From source file:com.github.fge.jsonschema.core.processing.CachingProcessor.java

/**
 * Main constructor/*from  w  w w  .j  a  v a  2s.  c  om*/
 *
 * @param processor the processor
 * @param equivalence an equivalence to use for cache keys
 * @param cacheSize the size of the cache, zero disables it
 * @throws NullPointerException processor or equivalence
 */
public CachingProcessor(final Processor<IN, OUT> processor, final Equivalence<IN> equivalence,
        final int cacheSize) {
    BUNDLE.checkNotNull(processor, "processing.nullProcessor");
    BUNDLE.checkNotNull(equivalence, "processing.nullEquivalence");
    BUNDLE.checkArgument(cacheSize >= -1, "processing.invalidCacheSize");
    this.processor = processor;
    this.equivalence = equivalence;
    CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
    if (cacheSize != -1) {
        builder.maximumSize(cacheSize);
    }
    cache = builder.build(loader());
}

From source file:org.jboss.weld.bootstrap.SpecializationAndEnablementRegistry.java

public SpecializationAndEnablementRegistry() {
    CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder();
    this.specializedBeanResolvers = cacheBuilder.build(new SpecializedBeanResolverForBeanManager());
    this.specializedBeans = cacheBuilder.build(new BeansSpecializedByBean());
}

From source file:com.brighttag.agathon.dao.zerg.ZergConnectorImpl.java

@Inject
public ZergConnectorImpl(@Named(ZergDaoModule.ZERG_MANIFEST_URL_PROPERTY) String manifestUrl,
        CacheBuilder<Object, Object> regionsCache, ZergConnectorImpl.ZergLoader loader) {
    this.manifestUrl = manifestUrl;
    this.regionsCache = regionsCache.build(loader);
}

From source file:org.intelligentsia.dowsers.core.memento.DefaultOriginatorRegistry.java

/**
 * Build a new instance of DefaultOriginatorRegistry.
 * //from   w w w  .  jav a 2 s. c om
 * @param cacheBuilder
 *            cache Builder instance.
 * @param defaultOriginator
 *            default Originator instance
 */
public DefaultOriginatorRegistry(final CacheBuilder<Object, Object> cacheBuilder, final Originator originator) {
    super();
    originators = Sets.newHashSet();
    defaultOriginator = Preconditions.checkNotNull(originator);
    cache = cacheBuilder.build(new CacheLoader<Class<?>, Originator>() {
        @Override
        public Originator load(final Class<?> key) throws Exception {
            for (final Originator originator : originators) {
                if (originator.support(key)) {
                    return originator;
                }
            }
            return defaultOriginator;
        }
    });
}

From source file:heros.FlowFunctionCache.java

@SuppressWarnings("unchecked")
public FlowFunctionCache(final FlowFunctions<N, D, M> delegate,
        @SuppressWarnings("rawtypes") CacheBuilder builder) {
    this.delegate = delegate;

    normalCache = builder.build(new CacheLoader<NNKey, FlowFunction<D>>() {
        public FlowFunction<D> load(NNKey key) throws Exception {
            return delegate.getNormalFlowFunction(key.getCurr(), key.getSucc());
        }//from w w  w . ja  v a2s.c om
    });

    callCache = builder.build(new CacheLoader<CallKey, FlowFunction<D>>() {
        public FlowFunction<D> load(CallKey key) throws Exception {
            return delegate.getCallFlowFunction(key.getCallStmt(), key.getDestinationMethod());
        }
    });

    returnCache = builder.build(new CacheLoader<ReturnKey, FlowFunction<D>>() {
        public FlowFunction<D> load(ReturnKey key) throws Exception {
            return delegate.getReturnFlowFunction(key.getCallStmt(), key.getDestinationMethod(),
                    key.getExitStmt(), key.getReturnSite());
        }
    });

    callToReturnCache = builder.build(new CacheLoader<NNKey, FlowFunction<D>>() {
        public FlowFunction<D> load(NNKey key) throws Exception {
            return delegate.getCallToReturnFlowFunction(key.getCurr(), key.getSucc());
        }
    });
}

From source file:com.github.fge.jsonschema.core.load.SchemaLoader.java

/**
 * Create a new schema loader with a given loading configuration
 *
 * @param cfg the configuration/*from  w  w w  . ja  v  a2 s .  c  o  m*/
 * @see LoadingConfiguration
 * @see LoadingConfigurationBuilder
 */
public SchemaLoader(final LoadingConfiguration cfg) {
    translator = new URITranslator(cfg.getTranslatorConfiguration());
    dereferencing = cfg.getDereferencing();
    manager = new URIManager(cfg);
    preloadedSchemas = ImmutableMap.copyOf(cfg.getPreloadedSchemas());

    CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
    if (cfg.getCacheSize() != -1) {
        builder.maximumSize(cfg.getCacheSize());
    }
    cache = builder.build(new CacheLoader<URI, JsonNode>() {
        @Nonnull
        @Override
        public JsonNode load(@Nonnull final URI key) throws ProcessingException {
            return manager.getContent(key);
        }
    });
}