当前位置: 首页>>代码示例>>Java>>正文


Java CaffeineSpec类代码示例

本文整理汇总了Java中com.github.benmanes.caffeine.cache.CaffeineSpec的典型用法代码示例。如果您正苦于以下问题:Java CaffeineSpec类的具体用法?Java CaffeineSpec怎么用?Java CaffeineSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CaffeineSpec类属于com.github.benmanes.caffeine.cache包,在下文中一共展示了CaffeineSpec类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCohortsPassedThrough

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
@Test
public void testCohortsPassedThrough() {
  final Toggle<Integer> mockToggle = mock(Toggle.class);
  when(mockToggle.withCohort(anyString())).thenReturn(mockToggle);
  when(mockToggle.test(eq(1))).thenReturn(toggle.test(1));
  when(underlying.apply(onKey)).thenReturn(mockToggle);

  final CachingToggleMap<String, Integer> toggleMap =
    new CachingToggleMap<>(underlying, CaffeineSpec.parse("maximumSize=3"));

  toggleMap.apply(onKey)
    .withCohort("foo")
    .test(1);

  verify(underlying, times(1)).apply(eq(onKey));
  verify(mockToggle, times(1)).withCohort(eq("foo"));
  verify(mockToggle, times(1)).test(eq(1));
}
 
开发者ID:whiskerlabs,项目名称:toggle,代码行数:19,代码来源:CachingToggleMapTest.java

示例2: validateCacheSpec

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
public static String validateCacheSpec(String cacheSpec) {
    if (cacheSpec == null) {
        return null;
    }

    try {
        CaffeineSpec.parse(cacheSpec);
        return cacheSpec;
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("cacheSpec: " + cacheSpec + " (" + e.getMessage() + ')');
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:13,代码来源:RepositoryCache.java

示例3: testReadFromUnderlyingToggleMapOnMiss

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
@Test
public void testReadFromUnderlyingToggleMapOnMiss() {
  when(underlying.apply(onKey)).thenReturn(toggle);

  final CachingToggleMap<String, Integer> toggleMap =
    new CachingToggleMap<>(underlying, CaffeineSpec.parse("maximumSize=3"));

  assertThat(toggleMap.apply(onKey).test(1)).isTrue();
  verify(underlying).apply(eq(onKey));
}
 
开发者ID:whiskerlabs,项目名称:toggle,代码行数:11,代码来源:CachingToggleMapTest.java

示例4: testReadFromCacheOnHit

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
@Test
public void testReadFromCacheOnHit() {
  when(underlying.apply(onKey)).thenReturn(toggle);

  final CachingToggleMap<String, Integer> toggleMap =
    new CachingToggleMap<>(underlying, CaffeineSpec.parse("maximumSize=3"));

  toggleMap.apply(onKey).test(1);
  toggleMap.apply(onKey).test(2);
  verify(underlying, times(1)).apply(eq(onKey));
}
 
开发者ID:whiskerlabs,项目名称:toggle,代码行数:12,代码来源:CachingToggleMapTest.java

示例5: testFallsBackToLastReadToggleOnFailedReadFromUnderlying

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
@Test
public void testFallsBackToLastReadToggleOnFailedReadFromUnderlying() {
  when(underlying.apply(onKey))
    .thenReturn(toggle)
    .thenThrow(new NoSuchElementException());

  final CachingToggleMap<String, Integer> toggleMap =
    new CachingToggleMap<>(underlying, CaffeineSpec.parse("maximumSize=0"));

  final Toggle<Integer> t = toggleMap.apply(onKey);
  assertThat(t.test(1)).isTrue();
  assertThat(t.test(1)).isTrue();
  verify(underlying, times(2)).apply(eq(onKey));
}
 
开发者ID:whiskerlabs,项目名称:toggle,代码行数:15,代码来源:CachingToggleMapTest.java

示例6: testReadKeySetFromUnderlying

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
@Test
public void testReadKeySetFromUnderlying() {
  final Set<String> expectedKeySet = new HashSet();
  expectedKeySet.add(onKey);
  expectedKeySet.add(offKey);
  when(underlying.keySet()).thenReturn(expectedKeySet);

  final CachingToggleMap<String, Integer> toggleMap =
    new CachingToggleMap<>(underlying, CaffeineSpec.parse("maximumSize=3"));

  assertThat(toggleMap.keySet()).containsOnly(onKey, offKey);
}
 
开发者ID:whiskerlabs,项目名称:toggle,代码行数:13,代码来源:CachingToggleMapTest.java

示例7: ProtobufRedisLoadingCache

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
ProtobufRedisLoadingCache(
    String name,
    K keyPrototype,
    V valuePrototype,
    Duration redisTtl,
    @Nullable CaffeineSpec localCacheSpec,
    RedisClusterClient redisClient) {
  checkNotNull(keyPrototype, "keyPrototype");
  checkNotNull(valuePrototype, "valuePrototype");
  checkNotNull(redisTtl, "redisTtl");
  checkNotNull(redisClient, "redisClient");
  redis =
      redisClient
          .connect(
              new ProtobufRedisCodec<>(
                  (name + ":").getBytes(StandardCharsets.UTF_8), keyPrototype, valuePrototype))
          .async();
  final Caffeine<Object, Object> caffeineBuilder =
      localCacheSpec != null
          ? Caffeine.from(localCacheSpec)
          : Caffeine.newBuilder().maximumSize(0);
  cache =
      caffeineBuilder
          .executor(CurrentRequestContextExecutor.INSTANCE)
          .buildAsync((k, executor) -> redis.get(k).toCompletableFuture());
  setArgs = SetArgs.Builder.px(redisTtl.toMillis());
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:28,代码来源:ProtobufRedisLoadingCache.java

示例8: caffeineSpec

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
/**
 * Default cache spec configuration for all the caches. The default cache
 * size is 200 and would expire after a min (60sec) of write operation.
 *
 * @return {@link CaffeineSpec}
 */
@Bean
public CaffeineSpec caffeineSpec() {
    CaffeineSpec spec = CaffeineSpec.parse("maximumSize=200,expireAfterWrite=300s");
    log.info("Using CaffeineSpec " + spec.toParsableString());
    return spec;
}
 
开发者ID:oneops,项目名称:secrets-proxy,代码行数:13,代码来源:CacheConfig.java

示例9: CaffeineCacheConfiguration

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
CaffeineCacheConfiguration(CacheProperties cacheProperties,
		CacheManagerCustomizers customizers,
		ObjectProvider<Caffeine<Object, Object>> caffeineProvider,
		ObjectProvider<CaffeineSpec> caffeineSpecProvider,
		ObjectProvider<CacheLoader<Object, Object>> cacheLoaderProvider) {
	this.cacheProperties = cacheProperties;
	this.customizers = customizers;
	this.caffeine = caffeineProvider.getIfAvailable();
	this.caffeineSpec = caffeineSpecProvider.getIfAvailable();
	this.cacheLoader = cacheLoaderProvider.getIfAvailable();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:CaffeineCacheConfiguration.java

示例10: caffeineSpec

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
private static Optional<String> caffeineSpec(String name, String defaultValue) {
    final String spec = get(name, defaultValue, value -> {
        try {
            if (!"off".equals(value)) {
                CaffeineSpec.parse(value);
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    });
    return "off".equals(spec) ? Optional.empty()
                              : Optional.of(spec);
}
 
开发者ID:line,项目名称:armeria,代码行数:15,代码来源:Flags.java

示例11: CachingToggleMap

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
public CachingToggleMap(ToggleMap<K, T> underlying, CaffeineSpec cacheSpec) {
  this.underlying = underlying;
  this.cache = Caffeine.from(cacheSpec)
    .build(underlying::apply);
  this.fallbackCache = new HashMap<>();
}
 
开发者ID:whiskerlabs,项目名称:toggle,代码行数:7,代码来源:CachingToggleMap.java

示例12: caffeineSpec

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
@Bean
CaffeineSpec caffeineSpec() {
	return CaffeineSpec.parse("recordStats");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:5,代码来源:CacheAutoConfigurationTests.java

示例13: create

import com.github.benmanes.caffeine.cache.CaffeineSpec; //导入依赖的package包/类
/**
 * Constructs a new {@link ProtobufRedisLoadingCache} that can write protobuf {@link Message}
 * keys and values to redis, with an optional local cache layer.
 *
 * @param name name of this cache, will be prefixed onto all keys.
 * @param keyPrototype a prototype for the key {@link Message}, usually gotten from {@code
 *     Key.getDefaultInstance()}.
 * @param valuePrototype a prototype for the value {@link Message}, usually gotten from {@code
 *     Value.getDefaultInstance()}.
 * @param redisTtl the time until expiration of a value in the redis cache. The local cache
 *     should be considered in localCacheSpec.
 * @param localCacheSpec a {@link CaffeineSpec} to control the local cache layer. If {@code
 *     null}, local caching will be disabled.
 */
public <K extends Message, V extends Message> ProtobufRedisLoadingCache<K, V> create(
    String name,
    K keyPrototype,
    V valuePrototype,
    Duration redisTtl,
    @Nullable CaffeineSpec localCacheSpec) {
  return new ProtobufRedisLoadingCache<>(
      name, keyPrototype, valuePrototype, redisTtl, localCacheSpec, redisClient);
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:24,代码来源:ProtobufRedisLoadingCache.java


注:本文中的com.github.benmanes.caffeine.cache.CaffeineSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。