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:de.rwhq.io.rm.CachedResourceManager.java

CachedResourceManager(final ResourceManager _rm, final int cacheSize) {
    checkNotNull(_rm);/*from  w  w  w. jav  a  2 s. c  o m*/
    checkArgument(cacheSize > 0, "cacheSize must be > 0");

    this.rm = _rm;
    this.cacheSize = cacheSize;
    this.cache = CacheBuilder.newBuilder().maximumSize(cacheSize)
            .removalListener(new RemovalListener<Integer, RawPage>() {
                @Override
                public void onRemoval(
                        final RemovalNotification<Integer, RawPage> integerRawPageRemovalNotification) {
                    final RawPage rawPage = integerRawPageRemovalNotification.getValue();
                    rawPage.sync();
                }
            }).build(new CacheLoader<Integer, RawPage>() {
                @Override
                public RawPage load(final Integer key) throws Exception {
                    return rm.getPage(key);
                }
            });

}

From source file:com.metamx.http.client.pool.ResourcePool.java

public ResourcePool(final ResourceFactory<K, V> factory, final ResourcePoolConfig config) {
    this.pool = CacheBuilder.newBuilder().build(new CacheLoader<K, ImmediateCreationResourceHolder<K, V>>() {
        @Override/*from  ww  w  .j a v a  2  s.c o  m*/
        public ImmediateCreationResourceHolder<K, V> load(K input) throws Exception {
            return new ImmediateCreationResourceHolder<K, V>(config.getMaxPerKey(), input, factory);
        }
    });
}

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

@Autowired
public CachingModelProvider(@Qualifier("default") final ModelProvider delegate) {
    this.delegate = delegate;
    cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(24, TimeUnit.HOURS)
            .build(new CacheLoader<ModelContext, Optional<Model>>() {
                public Optional<Model> load(ModelContext key) {
                    return delegate.modelFor(key);
                }/*  www.j  ava2 s .c  o m*/
            });
}

From source file:com.sinotopia.mybatis.pagehelper.cache.GuavaCache.java

public GuavaCache(Properties properties, String prefix) {

    CacheBuilder cacheBuilder = CacheBuilder.newBuilder();
    String maximumSize = properties.getProperty(prefix + ".maximumSize");
    if (StringUtil.isNotEmpty(maximumSize)) {
        cacheBuilder.maximumSize(Long.parseLong(maximumSize));
    } else {//from  w  w w.  j av  a 2 s  . com
        cacheBuilder.maximumSize(1000);
    }
    String expireAfterAccess = properties.getProperty(prefix + ".expireAfterAccess");
    if (StringUtil.isNotEmpty(expireAfterAccess)) {
        cacheBuilder.expireAfterAccess(Long.parseLong(expireAfterAccess), TimeUnit.MILLISECONDS);
    }
    String expireAfterWrite = properties.getProperty(prefix + ".expireAfterWrite");
    if (StringUtil.isNotEmpty(expireAfterWrite)) {
        cacheBuilder.expireAfterWrite(Long.parseLong(expireAfterWrite), TimeUnit.MILLISECONDS);
    }
    String initialCapacity = properties.getProperty(prefix + ".initialCapacity");
    if (StringUtil.isNotEmpty(initialCapacity)) {
        cacheBuilder.initialCapacity(Integer.parseInt(initialCapacity));
    }
    CACHE = cacheBuilder.build();
}

From source file:com.verymmog.demo.Data.java

public Data(MapClass map, PlayerInterface player, List<PlayerInterface> neighbours,
        List<PlayerInterface> podium) {
    this.map = map;
    this.player = player;
    players = CacheBuilder.newBuilder().expireAfterAccess(2L, TimeUnit.SECONDS)
            .build(CacheLoader.from(new Function<String, PlayerInterface>() {
                @Override/* ww  w.  j a va  2 s.c  o  m*/
                public PlayerInterface apply(String s) {
                    return new Player(0, 0, s);
                }
            }));
}

From source file:tech.beshu.ror.acl.definitions.externalauthenticationservices.CachedExternalAuthenticationServiceClient.java

private CachedExternalAuthenticationServiceClient(ExternalAuthenticationServiceClient underlying,
        Duration ttl) {/*from   ww  w  .  ja  v  a2 s.  c om*/
    this.underlying = underlying;
    this.cache = CacheBuilder.newBuilder().expireAfterWrite(ttl.toMillis(), TimeUnit.MILLISECONDS).build();
}

From source file:org.apache.people.mreutegg.mhmp.zh.TileRepository.java

TileRepository(File dir, String baseURL, Logger log) throws IOException {
    this.log = log;
    this.baseURL = baseURL;
    this.downloaded = mkdirs(dir);
    this.tileCache = CacheBuilder.newBuilder().maximumSize(16).build();
}

From source file:org.nmdp.gl.client.cache.CacheGlClientModule.java

@Provides
@GlClientLocusIdCache
protected Cache<String, String> createLocusIdCache() {
    return CacheBuilder.newBuilder().initialCapacity(1000).build();
}

From source file:io.prestosql.plugin.redis.RedisJedisManager.java

@Inject
RedisJedisManager(RedisConnectorConfig redisConnectorConfig, NodeManager nodeManager) {
    this.redisConnectorConfig = requireNonNull(redisConnectorConfig, "redisConfig is null");
    this.jedisPoolCache = CacheBuilder.newBuilder().build(CacheLoader.from(this::createConsumer));
    this.jedisPoolConfig = new JedisPoolConfig();
}

From source file:hambo.trident.state.LRUCachedMap.java

public LRUCachedMap(IBackingMap<T> delegate, int cacheSize) {
    _cache = CacheBuilder.newBuilder().maximumSize(cacheSize).build();
    _delegate = delegate;
}