com.github.benmanes.caffeine.cache.Caffeine.requireWeightWithWeigher()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中com.github.benmanes.caffeine.cache.Caffeine.requireWeightWithWeigher()方法的一些代码示例,展示了Caffeine.requireWeightWithWeigher()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Caffeine.requireWeightWithWeigher()方法的具体详情如下:
包路径:com.github.benmanes.caffeine.cache.Caffeine
类名称:Caffeine
方法名:requireWeightWithWeigher

Caffeine.requireWeightWithWeigher介绍

暂无

代码示例

代码示例来源:origin: ben-manes/caffeine

/**
 * Builds a cache which does not automatically load values when keys are requested unless a
 * mapping function is provided. Note that multiple threads can concurrently load values for
 * distinct keys.
 * <p>
 * Consider {@link #build(CacheLoader)} instead, if it is feasible to implement a
 * {@code CacheLoader}.
 * <p>
 * This method does not alter the state of this {@code Caffeine} instance, so it can be invoked
 * again to create multiple independent caches.
 *
 * @param <K1> the key type of the cache
 * @param <V1> the value type of the cache
 * @return a cache having the requested features
 */
@NonNull
public <K1 extends K, V1 extends V> Cache<K1, V1> build() {
 requireWeightWithWeigher();
 requireNonLoadingCache();
 @SuppressWarnings("unchecked")
 Caffeine<K1, V1> self = (Caffeine<K1, V1>) this;
 return isBounded()
   ? new BoundedLocalCache.BoundedLocalManualCache<>(self)
   : new UnboundedLocalCache.UnboundedLocalManualCache<>(self);
}

代码示例来源:origin: ben-manes/caffeine

"Weak or soft values can not be combined with AsyncLoadingCache");
requireState(writer == null, "CacheWriter can not be combined with AsyncLoadingCache");
requireWeightWithWeigher();
requireNonNull(loader);

代码示例来源:origin: ben-manes/caffeine

/**
 * Builds a cache, which either returns an already-loaded value for a given key or atomically
 * computes or retrieves it using the supplied {@code CacheLoader}. If another thread is currently
 * loading the value for this key, simply waits for that thread to finish and returns its loaded
 * value. Note that multiple threads can concurrently load values for distinct keys.
 * <p>
 * This method does not alter the state of this {@code Caffeine} instance, so it can be invoked
 * again to create multiple independent caches.
 *
 * @param loader the cache loader used to obtain new values
 * @param <K1> the key type of the loader
 * @param <V1> the value type of the loader
 * @return a cache having the requested features
 */
@NonNull
public <K1 extends K, V1 extends V> LoadingCache<K1, V1> build(
  @NonNull CacheLoader<? super K1, V1> loader) {
 requireWeightWithWeigher();
 @SuppressWarnings("unchecked")
 Caffeine<K1, V1> self = (Caffeine<K1, V1>) this;
 return isBounded() || refreshes()
   ? new BoundedLocalCache.BoundedLocalLoadingCache<>(self, loader)
   : new UnboundedLocalCache.UnboundedLocalLoadingCache<>(self, loader);
}

代码示例来源:origin: ben-manes/caffeine

requireState(valueStrength == null, "Weak or soft values can not be combined with AsyncCache");
requireState(writer == null, "CacheWriter can not be combined with AsyncCache");
requireWeightWithWeigher();
requireNonLoadingCache();

代码示例来源:origin: com.github.ben-manes.caffeine/caffeine

/**
 * Builds a cache, which either returns an already-loaded value for a given key or atomically
 * computes or retrieves it using the supplied {@code CacheLoader}. If another thread is currently
 * loading the value for this key, simply waits for that thread to finish and returns its loaded
 * value. Note that multiple threads can concurrently load values for distinct keys.
 * <p>
 * This method does not alter the state of this {@code Caffeine} instance, so it can be invoked
 * again to create multiple independent caches.
 *
 * @param loader the cache loader used to obtain new values
 * @param <K1> the key type of the loader
 * @param <V1> the value type of the loader
 * @return a cache having the requested features
 */
@Nonnull
public <K1 extends K, V1 extends V> LoadingCache<K1, V1> build(
  @Nonnull CacheLoader<? super K1, V1> loader) {
 requireWeightWithWeigher();
 @SuppressWarnings("unchecked")
 Caffeine<K1, V1> self = (Caffeine<K1, V1>) this;
 return isBounded() || refreshes()
   ? new BoundedLocalCache.BoundedLocalLoadingCache<>(self, loader)
   : new UnboundedLocalCache.UnboundedLocalLoadingCache<>(self, loader);
}

代码示例来源:origin: com.github.ben-manes.caffeine/caffeine

/**
 * Builds a cache which does not automatically load values when keys are requested.
 * <p>
 * Consider {@link #build(CacheLoader)} instead, if it is feasible to implement a
 * {@code CacheLoader}.
 * <p>
 * This method does not alter the state of this {@code Caffeine} instance, so it can be invoked
 * again to create multiple independent caches.
 *
 * @param <K1> the key type of the cache
 * @param <V1> the value type of the cache
 * @return a cache having the requested features
 */
@Nonnull
public <K1 extends K, V1 extends V> Cache<K1, V1> build() {
 requireWeightWithWeigher();
 requireNonLoadingCache();
 @SuppressWarnings("unchecked")
 Caffeine<K1, V1> self = (Caffeine<K1, V1>) this;
 return isBounded() || refreshes()
   ? new BoundedLocalCache.BoundedLocalManualCache<>(self)
   : new UnboundedLocalCache.UnboundedLocalManualCache<>(self);
}

代码示例来源:origin: com.github.ben-manes.caffeine/caffeine

"Weak or soft values can not be combined with AsyncLoadingCache");
requireState(writer == null, "CacheWriter can not be combined with AsyncLoadingCache");
requireWeightWithWeigher();
requireNonNull(loader);

相关文章