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.apache.usergrid.persistence.cache.impl.CacheFactoryImpl.java

@Inject
public CacheFactoryImpl(final ScopedCacheSerialization serializer) {

    cacheCache = CacheBuilder.newBuilder().maximumSize(1000).build(new CacheLoader<CacheScope, ScopedCache>() {
        public ScopedCache load(CacheScope scope) {
            return new ScopedCacheImpl(scope, serializer);
        }/*from w ww . j ava 2  s.co  m*/
    });
}

From source file:org.cryptomator.cryptofs.LongFileNameProvider.java

@Inject
public LongFileNameProvider(@PathToVault Path pathToVault) {
    this.metadataRoot = pathToVault.resolve(METADATA_DIR_NAME);
    this.ids = CacheBuilder.newBuilder().maximumSize(MAX_CACHE_SIZE).build(new Loader());
}

From source file:org.jclouds.cloudstack.suppliers.ZoneIdToZoneSupplier.java

@Inject
public ZoneIdToZoneSupplier(CacheLoader<String, Zone> zoneIdToZone,
        @Named(PROPERTY_SESSION_INTERVAL) long expirationSecs) {
    cache = CacheBuilder.newBuilder().expireAfterWrite(expirationSecs, TimeUnit.SECONDS).build(zoneIdToZone);
}

From source file:org.restheart.cache.impl.GuavaLoadingCache.java

public GuavaLoadingCache(long size, EXPIRE_POLICY expirePolicy, long ttl, Function<K, V> loader) {
    CacheBuilder builder = CacheBuilder.newBuilder();

    builder.maximumSize(size);/*from  w w  w  .j a v a 2s. c  o m*/

    if (ttl > 0 && expirePolicy == EXPIRE_POLICY.AFTER_WRITE) {
        builder.expireAfterWrite(ttl, TimeUnit.MILLISECONDS);
    } else if (ttl > 0 && expirePolicy == EXPIRE_POLICY.AFTER_READ) {
        builder.expireAfterAccess(ttl, TimeUnit.MILLISECONDS);
    }

    wrapped = builder.build(new CacheLoader<K, Optional<V>>() {
        @Override
        public Optional<V> load(K key) throws Exception {
            return Optional.ofNullable(loader.apply(key));
        }
    });
}

From source file:org.apache.zookeeper.inspector.manager.NodesCache.java

public NodesCache(ZooKeeper zooKeeper) {
    this.zooKeeper = zooKeeper;
    this.nodes = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE)
            .expireAfterWrite(EXPIRATION_TIME, TimeUnit.MILLISECONDS)
            .build(new CacheLoader<String, List<String>>() {
                @Override// w ww.j a  v  a 2  s  .  c  om
                public List<String> load(String nodePath) throws Exception {
                    return getChildren(nodePath);
                }
            });
}

From source file:se.uu.it.cs.recsys.semantic.config.ComputingDomainReasonerSpringConfig.java

@Bean
public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();

    GuavaCache fpTreeCache = new GuavaCache("ComputingDomainCache",
            CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS).maximumSize(100).build());

    cacheManager.setCaches(Stream.of(fpTreeCache).collect(Collectors.toList()));

    return cacheManager;
}

From source file:com.github.jcustenborder.kafka.connect.cdc.CachingTableMetadataProvider.java

public CachingTableMetadataProvider(T config, OffsetStorageReader offsetStorageReader) {
    this.config = config;
    this.tableMetadataCache = CacheBuilder.newBuilder()
            .expireAfterWrite(config.schemaCacheMs, TimeUnit.MILLISECONDS).build();
    this.offsetStorageReader = offsetStorageReader;
}

From source file:org.zhangmz.pickles.helper.AdminMainHelper.java

@PostConstruct
public void init() {
    logger.debug("?? " + loginTimeoutSecs);
    // CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(loginTimeoutSecs, TimeUnit.SECONDS).build();
    mainInfos = CacheBuilder.newBuilder().maximumSize(1000)
            .expireAfterAccess(loginTimeoutSecs, TimeUnit.SECONDS).build();
}

From source file:net.identio.server.service.oauth.infrastructure.InMemoryTokenRepository.java

public InMemoryTokenRepository() {

    tokenCache = CacheBuilder.newBuilder().maximumSize(100000).expireAfterAccess(1, TimeUnit.HOURS)
            .build(new CacheLoader<String, OAuthToken>() {
                public OAuthToken load(@Nonnull String o) {
                    return new OAuthToken();
                }/*from  www .j a v a2s. c  om*/
            });
}

From source file:com.google.api.auth.CachingJwksSupplier.java

@VisibleForTesting
CachingJwksSupplier(JwksSupplier jwksSupplier, Ticker ticker) {
    this.jwksCache = CacheBuilder.newBuilder().expireAfterWrite(CACHE_EXPIRATION_IN_MINUTES, TimeUnit.MINUTES)
            .ticker(ticker).build(new JwksCacheLoader(jwksSupplier));
}