List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:com.facebook.buck.rules.keys.DefaultRuleKeyBuilderFactory.java
public DefaultRuleKeyBuilderFactory(FileHashCache hashCache, SourcePathResolver pathResolver) { ruleKeyCache = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<RuleKeyAppendable, RuleKey>() { @Override//from w w w . ja v a2 s . c o m public RuleKey load(@Nonnull RuleKeyAppendable appendable) throws Exception { RuleKeyBuilder subKeyBuilder = newBuilder(); appendable.appendToRuleKey(subKeyBuilder); return subKeyBuilder.build(); } }); this.hashCache = hashCache; this.pathResolver = pathResolver; }
From source file:org.eclipse.che.multiuser.api.permission.server.HttpPermissionCheckerImpl.java
@Inject public HttpPermissionCheckerImpl(@Named("che.api") String apiEndpoint, HttpJsonRequestFactory requestFactory) { // TODO mb make configurable size of cache and expiration time this.permissionsCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(1, TimeUnit.MINUTES) .build(new CacheLoader<Key, Set<String>>() { @Override/* w ww .ja v a 2s.c om*/ public Set<String> load(Key key) throws Exception { UriBuilder currentUsersPermissions = UriBuilder.fromUri(apiEndpoint) .path("permissions/" + key.domain); if (key.instance != null) { currentUsersPermissions.queryParam("instance", key.instance); } String userPermissionsUrl = currentUsersPermissions.build().toString(); try { PermissionsDto usersPermissions = requestFactory.fromUrl(userPermissionsUrl) .useGetMethod().request().asDto(PermissionsDto.class); return new HashSet<>(usersPermissions.getActions()); } catch (NotFoundException e) { // user doesn't have permissions return new HashSet<>(); } } }); }
From source file:com.spotify.dns.RetainingDnsSrvResolver.java
RetainingDnsSrvResolver(DnsSrvResolver delegate, long retentionTimeMillis) { Preconditions.checkArgument(retentionTimeMillis > 0L, "retention time must be positive, was %d", retentionTimeMillis);/* w ww . j a va 2 s . c o m*/ this.delegate = Preconditions.checkNotNull(delegate, "delegate"); cache = CacheBuilder.newBuilder().expireAfterWrite(retentionTimeMillis, TimeUnit.MILLISECONDS).build(); }
From source file:org.glowroot.agent.impl.ServiceRegistryImpl.java
private ServiceRegistryImpl(GlowrootService glowrootService, TimerNameCache timerNameCache, final ConfigServiceFactory configServiceFactory) { this.glowrootService = glowrootService; this.timerNameCache = timerNameCache; configServices = CacheBuilder.newBuilder().build(new CacheLoader<String, ConfigService>() { @Override/*from ww w . j a va2 s. c o m*/ public ConfigService load(String pluginId) { return configServiceFactory.create(pluginId); } }); }
From source file:io.crate.execution.engine.indexing.IndexNameResolver.java
private static Supplier<String> forPartition(final TableIdent tableIdent, final List<Input<?>> partitionedByInputs) { assert partitionedByInputs.size() > 0 : "must have at least 1 partitionedByInput"; final LoadingCache<List<BytesRef>, String> cache = CacheBuilder.newBuilder().initialCapacity(10) .maximumSize(20).build(new CacheLoader<List<BytesRef>, String>() { @Override/*ww w. j a va 2 s .co m*/ public String load(@Nonnull List<BytesRef> key) throws Exception { return IndexParts.toIndexName(tableIdent, PartitionName.encodeIdent(key)); } }); return () -> { // copy because the values of the inputs are mutable List<BytesRef> partitions = Lists2.copyAndReplace(partitionedByInputs, Inputs.TO_BYTES_REF); return cache.getUnchecked(partitions); }; }
From source file:org.jboss.hal.meta.security.SecurityContextRegistry.java
@Inject public SecurityContextRegistry(StatementContext statementContext, Environment environment) { super(new SecurityContextStatementContext(statementContext, environment), SECURITY_CONTEXT_TYPE); this.cache = CacheBuilder .newBuilder().maximumSize(CACHE_SIZE).recordStats().removalListener(notification -> logger .debug("Remove {} from {} cache: {}", notification.getKey(), type, notification.getCause())) .build();/*from w w w .j a v a 2 s . co m*/ }
From source file:org.xacml4j.v30.spi.pip.DefaultPolicyInformationPointCacheProvider.java
public DefaultPolicyInformationPointCacheProvider(int maxAttrSize, int maxContentSize) { this.attributeCache = CacheBuilder.newBuilder().maximumSize(maxAttrSize).build(); this.contentCache = CacheBuilder.newBuilder().maximumSize(maxContentSize).build(); }
From source file:org.ttrssreader.imageCache.ImageCache.java
public ImageCache(int initialCapacity, String cacheDir) { this.diskCacheDir = cacheDir; this.cache = CacheBuilder.newBuilder().initialCapacity(initialCapacity).concurrencyLevel(1).softValues() .build(new CacheLoader<String, Byte[]>() { @Override// ww w . j ava 2 s . c o m public Byte[] load(String key) throws Exception { return null; } }); }
From source file:org.mule.module.http.internal.request.client.HttpConnectorMessageProcessorProvider.java
public HttpConnectorMessageProcessorProvider() { cachedMessageProcessors = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE) .expireAfterWrite(EXPIRATION_TIME_IN_MINUTES, TimeUnit.MINUTES) .build(new CacheLoader<HttpRequestCacheKey, MessageProcessor>() { public MessageProcessor load(HttpRequestCacheKey cacheKey) throws MuleException { return buildMessageProcessor(cacheKey); }// w w w . j a v a 2 s .c om }); }
From source file:org.opendaylight.sloth.cache.SlothDomainCache.java
public SlothDomainCache(DataBroker dataBroker) { super(dataBroker); registerListener(LogicalDatastoreType.CONFIGURATION, SLOTH_DOMAIN_ID); domainCache = CacheBuilder.newBuilder().maximumSize(MAX_DOMAIN_CACHE).build(); LOG.info("initialize SlothDomainCache"); }