下面列出了com.google.common.cache.CacheLoader#from ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static CacheLoader<Pair<Class<RelNode>, Class<Metadata>>,
UnboundMetadata<Metadata>> loader(final RelMetadataProvider provider) {
return CacheLoader.from(key -> {
final UnboundMetadata<Metadata> function =
provider.apply(key.left, key.right);
// Return DUMMY, not null, so the cache knows to not ask again.
return function != null ? function : DUMMY;
});
}
private static CacheLoader<Pair<Class<RelNode>, Class<Metadata>>,
UnboundMetadata<Metadata>> loader(final RelMetadataProvider provider) {
return CacheLoader.from(key -> {
final UnboundMetadata<Metadata> function =
provider.apply(key.left, key.right);
// Return DUMMY, not null, so the cache knows to not ask again.
return function != null ? function : DUMMY;
});
}
public CachedSpecService(CoreSpecService coreService, StoreProto.Store store) {
this.coreService = coreService;
this.store = coreService.registerStore(store);
Map<String, FeatureSetSpec> featureSets = getFeatureSetMap();
featureToFeatureSetMapping =
new ConcurrentHashMap<>(getFeatureToFeatureSetMapping(featureSets));
CacheLoader<String, FeatureSetSpec> featureSetCacheLoader = CacheLoader.from(featureSets::get);
featureSetCache =
CacheBuilder.newBuilder().maximumSize(MAX_SPEC_COUNT).build(featureSetCacheLoader);
featureSetCache.putAll(featureSets);
}
private LoadingCache<UnorderedPair<T>, Double> createCache() {
CacheLoader<UnorderedPair<T>, Double> loader = CacheLoader
.from(similarityMeasure::calculateSimilarity);
return CacheBuilder.newBuilder()
.maximumSize(maximumSize)
.build(loader);
}
private static CacheLoader<Pair<Class<RelNode>, Class<Metadata>>,
UnboundMetadata<Metadata>> loader(final RelMetadataProvider provider) {
return CacheLoader.from(key -> {
final UnboundMetadata<Metadata> function =
provider.apply(key.left, key.right);
// Return DUMMY, not null, so the cache knows to not ask again.
return function != null ? function : DUMMY;
});
}
private LoadingCache<GreaterOrEqualCall, IntCollection> createCache() {
CacheLoader<GreaterOrEqualCall, IntCollection> loader = CacheLoader
.from(GreaterOrEqualCall::call);
return CACHE_BUILDER.build(loader);
}