Search in sources :

Example 6 with CacheBuilder

use of org.apache.flink.shaded.guava30.com.google.common.cache.CacheBuilder in project samza by apache.

the class CachingTableProvider method createDefaultCacheTable.

private ReadWriteUpdateTable createDefaultCacheTable(String tableId, JavaTableConfig tableConfig) {
    long readTtlMs = Long.parseLong(tableConfig.getForTable(tableId, CachingTableDescriptor.READ_TTL_MS, "-1"));
    long writeTtlMs = Long.parseLong(tableConfig.getForTable(tableId, CachingTableDescriptor.WRITE_TTL_MS, "-1"));
    long cacheSize = Long.parseLong(tableConfig.getForTable(tableId, CachingTableDescriptor.CACHE_SIZE, "-1"));
    CacheBuilder cacheBuilder = CacheBuilder.newBuilder();
    if (readTtlMs != -1) {
        cacheBuilder.expireAfterAccess(readTtlMs, TimeUnit.MILLISECONDS);
    }
    if (writeTtlMs != -1) {
        cacheBuilder.expireAfterWrite(writeTtlMs, TimeUnit.MILLISECONDS);
    }
    if (cacheSize != -1) {
        cacheBuilder.maximumSize(cacheSize);
    }
    logger.info(String.format("Creating default cache with: readTtl=%d, writeTtl=%d, maxSize=%d", readTtlMs, writeTtlMs, cacheSize));
    GuavaCacheTable cacheTable = new GuavaCacheTable(tableId + "-def-cache", cacheBuilder.build());
    cacheTable.init(this.context);
    return cacheTable;
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) GuavaCacheTable(org.apache.samza.table.caching.guava.GuavaCacheTable)

Example 7 with CacheBuilder

use of org.apache.flink.shaded.guava30.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 8 with CacheBuilder

use of org.apache.flink.shaded.guava30.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)

Example 9 with CacheBuilder

use of org.apache.flink.shaded.guava30.com.google.common.cache.CacheBuilder in project nifi by apache.

the class TransformXml method onScheduled.

@OnScheduled
public void onScheduled(final ProcessContext context) {
    final ComponentLog logger = getLogger();
    final Integer cacheSize = context.getProperty(CACHE_SIZE).asInteger();
    final Long cacheTTL = context.getProperty(CACHE_TTL_AFTER_LAST_ACCESS).asTimePeriod(TimeUnit.SECONDS);
    if (cacheSize > 0) {
        CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(cacheSize);
        if (cacheTTL > 0) {
            cacheBuilder = cacheBuilder.expireAfterAccess(cacheTTL, TimeUnit.SECONDS);
        }
        cache = cacheBuilder.build(new CacheLoader<String, Templates>() {

            public Templates load(String path) throws TransformerConfigurationException {
                return newTemplates(context, path);
            }
        });
    } else {
        cache = null;
        logger.warn("Stylesheet cache disabled because cache size is set to 0");
    }
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) CacheLoader(com.google.common.cache.CacheLoader) ComponentLog(org.apache.nifi.logging.ComponentLog) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 10 with CacheBuilder

use of org.apache.flink.shaded.guava30.com.google.common.cache.CacheBuilder in project summerb by skarpushin.

the class SimplePropertyServiceCachedImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    String jmxName = "SimplePropertyServiceCachedImpl_" + simplePropertyService.getAppName() + "_" + simplePropertyService.getDomainName();
    CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(5000).recordStats();
    cache = new TransactionBoundCache<>(jmxName, cacheBuilder, loader);
    eventBus.register(this);
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder)

Aggregations

CacheBuilder (com.google.common.cache.CacheBuilder)12 CacheLoader (com.google.common.cache.CacheLoader)2 CacheBackedStorageManager (com.hortonworks.registries.storage.CacheBackedStorageManager)2 Storable (com.hortonworks.registries.storage.Storable)2 StorableKey (com.hortonworks.registries.storage.StorableKey)2 StorageManager (com.hortonworks.registries.storage.StorageManager)2 StorageWriter (com.hortonworks.registries.storage.cache.writer.StorageWriter)2 InMemoryStorageManager (com.hortonworks.registries.storage.impl.memory.InMemoryStorageManager)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 ComponentLog (org.apache.nifi.logging.ComponentLog)1 GuavaCacheTable (org.apache.samza.table.caching.guava.GuavaCacheTable)1 Test (org.junit.Test)1 Bean (org.springframework.context.annotation.Bean)1 User (org.summerb.microservices.users.api.dto.User)1 User (org.summerb.users.api.dto.User)1