List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:org.ratpackframework.groovy.templating.internal.GroovyTemplateRenderingEngine.java
@Inject public GroovyTemplateRenderingEngine(TemplatingConfig templatingConfig) { this.compiledTemplateCache = CacheBuilder.newBuilder().maximumSize(templatingConfig.getCacheSize()).build(); checkTimestamp = templatingConfig.isCheckTimestamp(); ScriptEngine<TemplateScript> scriptEngine = new ScriptEngine<TemplateScript>(getClass().getClassLoader(), templatingConfig.isStaticallyCompile(), TemplateScript.class); templateCompiler = new TemplateCompiler(scriptEngine); }
From source file:name.martingeisse.stackd.server.section.storage.FolderBasedSectionStorage.java
/** * Constructor.//from w w w . jav a2 s. c o m * @param clusterSize the cluster-size of sections * @param storageFolder the folder that contains world storage files */ public FolderBasedSectionStorage(final ClusterSize clusterSize, final File storageFolder) { super(clusterSize); this.storageFolder = storageFolder; this.fileHandleCache = CacheBuilder.newBuilder().maximumSize(100) .removalListener(new RemovalListener<SectionId, RandomAccessFile>() { @Override public void onRemoval(RemovalNotification<SectionId, RandomAccessFile> notification) { try { notification.getValue().close(); } catch (IOException e) { } } }).build(new CacheLoader<SectionId, RandomAccessFile>() { @Override public RandomAccessFile load(SectionId superSectionId) throws Exception { File file = getSectionFile(superSectionId); // create an empty file if there is none yet if (!file.exists()) { final FileOutputStream fileOutputStream = new FileOutputStream(file); try { final byte[] emptyToc = new byte[16 * 16 * 16 * 3 * 4]; fileOutputStream.write(emptyToc); } finally { fileOutputStream.close(); } } return new RandomAccessFile(file, "rw"); } }); }
From source file:org.cryptomator.cryptofs.CryptoPathMapper.java
@Inject public CryptoPathMapper(@PathToVault Path pathToVault, Cryptor cryptor, DirectoryIdProvider dirIdProvider, LongFileNameProvider longFileNameProvider) { this.dataRoot = pathToVault.resolve(DATA_DIR_NAME); this.cryptor = cryptor; this.dirIdProvider = dirIdProvider; this.longFileNameProvider = longFileNameProvider; this.directoryPathCache = CacheBuilder.newBuilder().maximumSize(MAX_CACHED_DIR_PATHS) .build(CacheLoader.from(this::resolveDirectory)); }
From source file:com.facebook.buck.apple.AppleDependenciesCache.java
public AppleDependenciesCache(TargetGraph projectGraph) { this.depsCache = CacheBuilder.newBuilder().build(CacheLoader.from(node -> { ImmutableSortedSet.Builder<TargetNode<?, ?>> defaultDepsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<TargetNode<?, ?>> exportedDepsBuilder = ImmutableSortedSet.naturalOrder(); AppleBuildRules.addDirectAndExportedDeps(projectGraph, node, defaultDepsBuilder, exportedDepsBuilder); return new CacheItem(defaultDepsBuilder.build(), exportedDepsBuilder.build()); }));/* www . j a va2 s . com*/ }
From source file:com.facebook.buck.rules.keys.AbiRuleKeyFactory.java
public AbiRuleKeyFactory(int seed, FileHashLoader hashLoader, SourcePathResolver pathResolver, DefaultRuleKeyFactory defaultRuleKeyFactory) { super(seed);/* w w w.j a va 2 s .c om*/ this.ruleKeyCache = CacheBuilder.newBuilder().weakKeys() .build(new CacheLoader<RuleKeyAppendable, RuleKey>() { @Override public RuleKey load(@Nonnull RuleKeyAppendable appendable) throws Exception { RuleKeyBuilder<RuleKey> subKeyBuilder = newBuilder(); appendable.appendToRuleKey(subKeyBuilder); return subKeyBuilder.build(); } }); this.hashLoader = hashLoader; this.pathResolver = pathResolver; this.defaultRuleKeyFactory = defaultRuleKeyFactory; }
From source file:org.trimou.engine.cache.DefaultComputingCacheFactory.java
@Override public <K, V> ComputingCache<K, V> create(final String consumerId, final Function<K, V> computingFunction, final Long expirationTimeout, final Long maxSize, final Listener<K> listener) { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); if (expirationTimeout != null && expirationTimeout > 0) { builder.expireAfterWrite(expirationTimeout, TimeUnit.MILLISECONDS); }//from ww w . ja v a2 s . c om if (maxSize != null) { builder.maximumSize(maxSize); } if (listener != null) { builder.removalListener(new RemovalListener<K, V>() { @Override public void onRemoval(RemovalNotification<K, V> notification) { listener.entryInvalidated(notification.getKey(), notification.getCause().toString()); } }); } return new LoadingCacheAdapter<K, V>(builder.build(new CacheLoaderAdapter<K, V>(computingFunction))); }
From source file:com.facebook.buck.core.cell.CellProvider.java
/** * Create a cell provider with a specific cell loader, and optionally a special factory function * for the root cell./*from w w w .j ava 2 s . c o m*/ * * <p>The indirection for passing in CellProvider allows cells to reference the current * CellProvider object. */ public CellProvider(Function<CellProvider, CacheLoader<Path, Cell>> cellCacheLoader, @Nullable Function<CellProvider, Cell> rootCellLoader) { this.cells = CacheBuilder.newBuilder().build(cellCacheLoader.apply(this)); if (rootCellLoader != null) { Cell rootCell = rootCellLoader.apply(this); cells.put(rootCell.getRoot(), rootCell); } }
From source file:org.apache.gobblin.hive.HiveMetastoreClientPool.java
private static final Cache<Optional<String>, HiveMetastoreClientPool> createPoolCache( final Properties properties) { long duration = properties.containsKey(POOL_CACHE_TTL_MINUTES_KEY) ? Long.parseLong(properties.getProperty(POOL_CACHE_TTL_MINUTES_KEY)) : DEFAULT_POOL_CACHE_TTL_MINUTES; return CacheBuilder.newBuilder().expireAfterAccess(duration, TimeUnit.MINUTES) .removalListener(new RemovalListener<Optional<String>, HiveMetastoreClientPool>() { @Override// w w w. j a v a 2 s. co m public void onRemoval( RemovalNotification<Optional<String>, HiveMetastoreClientPool> notification) { if (notification.getValue() != null) { notification.getValue().close(); } } }).build(); }
From source file:com.facebook.buck.rules.keys.AbstractRuleKeyBuilderFactory.java
public AbstractRuleKeyBuilderFactory(FileHashCache hashCache, SourcePathResolver pathResolver) { this.hashCache = hashCache; this.pathResolver = pathResolver; knownFields = CacheBuilder.newBuilder().build(new ReflectiveAlterKeyLoader()); }
From source file:kr.debop4j.core.cache.ConcurrentHashMapCacheRepository.java
/** * Instantiates a new Concurrent hash map cache repository. * * @param validFor the valid for/* w w w. j a va 2 s. com*/ */ public ConcurrentHashMapCacheRepository(long validFor) { if (validFor > 0) setExpiry(validFor); CacheBuilder builder = CacheBuilder.newBuilder().concurrencyLevel(4); if (validFor > 0) builder.expireAfterAccess(validFor, TimeUnit.MINUTES); cache = builder.build(); }