@Override public LoadingCache<CacheKey, List<TransientActionFactory<?>>> load(final ExtensionList<TransientActionFactory> allFactories) throws Exception { final LoadingCache<CacheKey, List<TransientActionFactory<?>>> perJenkinsCache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<TransientActionFactory<?>>>() { @Override public List<TransientActionFactory<?>> load(CacheKey key) throws Exception { List<TransientActionFactory<?>> factories = new ArrayList<>(); for (TransientActionFactory<?> taf : allFactories) { Class<? extends Action> actionType = taf.actionType(); if (taf.type().isAssignableFrom(key.type) && (key.actionType.isAssignableFrom(actionType) || actionType.isAssignableFrom(key.actionType))) { factories.add(taf); } } return factories; } }); allFactories.addListener(new ExtensionListListener() { @Override public void onChange() { perJenkinsCache.invalidateAll(); } }); return perJenkinsCache; } });
@Override public LoadingCache<O, Set<MappingBo<O, T>>> load(String key) throws Exception { return CacheBuilder.newBuilder() .build(new CacheLoader<O, Set<MappingBo<O, T>>>() { @Override public Set<MappingBo<O, T>> load(O key) throws Exception { return new HashSet<>(); } }); } });
@Override public LoadingCache<WaveletId, PerWavelet> load(final WaveId waveId) { return CacheBuilder.newBuilder().build(new CacheLoader<WaveletId, PerWavelet>() { @Override public PerWavelet load(WaveletId waveletId) { WaveletName waveletName = WaveletName.of(waveId, waveletId); return new PerWavelet(waveletName, hashedVersionFactory .createVersionZero(waveletName)); } }); } });
@Override public LoadingCache<String, AggregatedMetricsEmitter> load(Map<String, String> tags) throws Exception { return CacheBuilder.newBuilder().expireAfterAccess(CACHE_EXPIRE_MINUTES, TimeUnit.MINUTES). build(new CacheLoader<String, AggregatedMetricsEmitter>() { @Override public AggregatedMetricsEmitter load(String metricName) throws Exception { return new AggregatedMetricsEmitter(metricName); } }); } });
@Override public LoadingCache<T, Set<MappingBo<O, T>>> load(String key) throws Exception { return CacheBuilder.newBuilder() .build(new CacheLoader<T, Set<MappingBo<O, T>>>() { @Override public Set<MappingBo<O, T>> load(T key) throws Exception { return new HashSet<>(); } }); } });
@Override public LoadingCache<T, Set<MappingBo<O, T>>> load(String key) throws Exception { return CacheBuilder.newBuilder() .build(new CacheLoader<T, Set<MappingBo<O, T>>>() { @Override public Set<MappingBo<O, T>> load(T key) throws Exception { return new HashSet<>(); } }); } });
@Override public LoadingCache<String, Class<?>> load(ClassLoader loader) { return CacheBuilder.newBuilder() .build(new CacheLoader<String, Class<?>>() { @Override public Class<?> load(String className) throws ClassNotFoundException { return Class.forName(className, false, loader); } }); } });
@Override public LoadingCache<CachingWire.Query, Response> load( final Wire key) { return CacheBuilder.newBuilder().build( new CacheLoader<CachingWire.Query, Response>() { @Override public Response load(final CachingWire.Query query) throws IOException { return query.fetch(); } } ); } };
@Override public LoadingCache<String, AggregatedMetricsEmitter> load(Map<String, String> tags) throws Exception { return CacheBuilder.newBuilder().expireAfterAccess(CACHE_EXPIRE_MINUTES, TimeUnit.MINUTES). build(new CacheLoader<String, AggregatedMetricsEmitter>() { @Override public AggregatedMetricsEmitter load(String metricName) throws Exception { return new AggregatedMetricsEmitter(metricName); } }); } });
@Override public LoadingCache<CacheEntryTag, Set<Object>> load(String key) throws Exception { // Key Tag -> Set of Tagged Cache Keys return CacheBuilder.newBuilder() .build( new CacheLoader<CacheEntryTag, Set<Object>>() { @Override public Set<Object> load(CacheEntryTag key) throws Exception { // Set of Tagged Cache Keys return Collections.newSetFromMap( new MapMaker() .weakKeys() .<Object, Boolean> makeMap()); } }); } });
@Override public LoadingCache<String, Optional<Class<?>>> load(final Optional<ClassLoader> loader) { return CacheBuilder.newBuilder().build(new CacheLoader<String, Optional<Class<?>>>() { @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Optional<Class<?>> load(String className) { try { return (Optional) Optional.of((Class) Class.forName(className, false, loader.orNull())); } catch (ClassNotFoundException error) { // Falls through to return absent below. } catch (NoClassDefFoundError error) { // Falls through to return absent below. } return Optional.absent(); } }); } });
@Override public LoadingCache<CacheEntryTag, Set<Object>> load(String key) throws Exception { // Key Tag -> Set of Tagged Cache Keys return CacheBuilder.newBuilder() .build( new CacheLoader<CacheEntryTag, Set<Object>>() { @Override public Set<Object> load(CacheEntryTag key) throws Exception { // Set of Tagged Cache Keys return Collections.newSetFromMap( new MapMaker() .weakKeys() .<Object, Boolean> makeMap()); } }); } });
@Override public LoadingCache<String, Class<?>> load(final ClassLoader classloader) { return CacheBuilder.newBuilder().weakValues().build(new CacheLoader<String, Class<?>>() { @Override public Class<?> load(String fullQualifiedName) throws ClassNotFoundException { return Class.forName(fullQualifiedName, false, classloader); } }); }
public static <K, V> CacheLoader<K, V> asyncReload(final CacheLoader<K, V> loader, final Executor executor) { checkNotNull(loader); checkNotNull(executor); return new CacheLoader<K, V>() { @Override public V load(K key) throws Exception { return loader.load(key); } @Override public ListenableFuture<V> reload(final K key, final V oldValue) throws Exception { ListenableFutureTask<V> task = ListenableFutureTask.create(new Callable<V>() { @Override public V call() throws Exception { System.out.println("async impl load"); return loader.reload(key, oldValue).get(); } }); executor.execute(task); return task; } @Override public Map<K, V> loadAll(Iterable<? extends K> keys) throws Exception { return loader.loadAll(keys); } }; }
@Override public LoadingCache<Object, Object> load(final Object key) throws Exception { return CacheBuilder.newBuilder().weakKeys().build( new CacheLoader<Object, Object>() { @Override public Object load(final Object key) throws Exception { return new Object(); } } ); } });
@Override @ParametersAreNonnullByDefault public LoadingCache<ClassLoader, LoadingCache<Class<?>, Set<?>>> load(ClassFinder finder) { return CacheBuilder.newBuilder() .weakKeys() .build(new CacheLoader<ClassLoader, LoadingCache<Class<?>, Set<?>>>() { @Override @ParametersAreNonnullByDefault public LoadingCache<Class<?>, Set<?>> load(final ClassLoader loader) { return CacheBuilder.newBuilder() .weakKeys() .build(new CacheLoader<Class<?>, Set<?>>() { @Override @ParametersAreNonnullByDefault public Set<?> load(Class<?> baseClass) { return finder.find(loader, baseClass); } }); } }); } });
@Override public LoadingCache<CacheKey, List<TransientActionFactory<?>>> load(final ExtensionList<TransientActionFactory> allFactories) throws Exception { final LoadingCache<CacheKey, List<TransientActionFactory<?>>> perJenkinsCache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<TransientActionFactory<?>>>() { @Override public List<TransientActionFactory<?>> load(CacheKey key) throws Exception { List<TransientActionFactory<?>> factories = new ArrayList<>(); for (TransientActionFactory<?> taf : allFactories) { Class<? extends Action> actionType = taf.actionType(); if (taf.type().isAssignableFrom(key.type) && (key.actionType.isAssignableFrom(actionType) || actionType.isAssignableFrom(key.actionType))) { factories.add(taf); } } return factories; } }); allFactories.addListener(new ExtensionListListener() { @Override public void onChange() { perJenkinsCache.invalidateAll(); } }); return perJenkinsCache; } });
.build(new CacheLoader<SessionIdentifier, Session>() { @Override public Session load(SessionIdentifier sessionKey)