public static CaffeineCache create(final CaffeineCacheConfig config, final Executor executor)
  {
    Caffeine<Object, Object> builder = Caffeine.newBuilder().recordStats();
    if (config.getExpireAfter() >= 0) {
      builder
          .expireAfterAccess(config.getExpireAfter(), TimeUnit.MILLISECONDS);
    }
    if (config.getSizeInBytes() >= 0) {
      builder.maximumWeight(config.getSizeInBytes());
    } else {
      builder.maximumWeight(Math.min(MAX_DEFAULT_BYTES, JvmUtils.getRuntimeInfo().getMaxHeapSizeBytes() / 10));
    }
    builder
        .weigher((NamedKey key, byte[] value) -> value.length
                                                 + key.key.length
                                                 + key.namespace.length() * Character.BYTES
                                                 + FIXED_COST)
        .executor(executor);
    return new CaffeineCache(builder.build(), config);
  }
public static CaffeineCache create ( final CaffeineCacheConfig config , final Executor executor ) { Caffeine < Object , Object > builder = Caffeine . newBuilder ( ) . recordStats ( ) ; if ( config . getExpireAfter ( ) >= 0 ) { builder . expireAfterAccess ( config . getExpireAfter ( ) , TimeUnit . MILLISECONDS ) ; } if ( config . getSizeInBytes ( ) >= 0 ) { builder . maximumWeight ( config . getSizeInBytes ( ) ) ; } else { builder . maximumWeight ( Math . min ( MAX_DEFAULT_BYTES , JvmUtils . getRuntimeInfo ( ) . getMaxHeapSizeBytes ( ) / 10 ) ) ; } builder . weigher ( ( NamedKey key , byte [ ] value ) -> value . length + key . key . length + key . namespace . length ( ) * Character . BYTES + FIXED_COST ) . executor ( executor ) ; return new CaffeineCache ( builder . build ( ) , config ) ; }
Used in testing