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;
}
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());
}
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);
}
});
}
}
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");
}
}
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);
}
Aggregations