Search in sources :

Example 1 with CacheBuilder

use of com.google.common.cache.CacheBuilder in project pinpoint by naver.

the class GuavaCacheTest method test.

@Test
public void test() {
    CacheBuilder builder = CacheBuilder.newBuilder();
    builder.concurrencyLevel(8);
    builder.maximumSize(1);
    builder.initialCapacity(1);
    Cache<String, Object> cache = builder.build();
    cache.put("test1", "1");
    logger.debug("{}", cache.size());
    cache.put("test3", "2");
    logger.debug("{}", cache.size());
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) Test(org.junit.Test)

Example 2 with CacheBuilder

use of com.google.common.cache.CacheBuilder in project opennms by OpenNMS.

the class NodeCacheImpl method init.

public void init() {
    if (cache == null) {
        LOG.info("initializing node data cache (archiveAssetData=" + archiveAssetData + ", TTL=" + MAX_TTL + "m, MAX_SIZE=" + MAX_SIZE + ")");
        CacheBuilder cacheBuilder = CacheBuilder.newBuilder();
        if (MAX_TTL > 0) {
            cacheBuilder.expireAfterWrite(MAX_TTL, TimeUnit.MINUTES);
        }
        if (MAX_SIZE > 0) {
            cacheBuilder.maximumSize(MAX_SIZE);
        }
        cache = cacheBuilder.build(new CacheLoader<Long, Map<String, String>>() {

            @Override
            public Map<String, String> load(Long key) throws Exception {
                return getNodeAndCategoryInfo(key);
            }
        });
    }
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) CacheLoader(com.google.common.cache.CacheLoader)

Aggregations

CacheBuilder (com.google.common.cache.CacheBuilder)2 CacheLoader (com.google.common.cache.CacheLoader)1 Test (org.junit.Test)1