@Test public void shouldMemoizeConsumer() { final Consumer<String> consumer = Mockito.mock(Consumer.class); final Function<String, String> keyFunction = Function.identity(); try (final Cache<String, String> cache = JCacheMemoize.createCache(Consumer.class)) { final JCacheBasedConsumerMemoizer<String, String> loader = new JCacheBasedConsumerMemoizer<>(cache, keyFunction, consumer); loader.accept("test"); Mockito.verify(consumer).accept("test"); } }
@Override public void accept(final INPUT input) { final KEY key = keyFunction.apply(input); invoke(key, givenKey -> { consumer.accept(input); return input; }); }
JCacheBasedConsumerMemoizer extends AbstractJCacheBasedMemoizer<KEY, INPUT> implements Consumer<INPUT> { @Override public void accept(final INPUT input) { final KEY key = keyFunction.apply(input); invoke(key, givenKey -> { consumer.accept(input); return input; }); } }
JCacheBasedConsumerMemoizer extends AbstractJCacheBasedMemoizer<KEY, INPUT> implements Consumer<INPUT> { @Override public void accept(final INPUT input) { final KEY key = keyFunction.apply(input); invoke(key, givenKey -> { consumer.accept(input); return input; }); } JCacheBasedConsumerMemoizer(
            final Cache<KEY, INPUT> cache,
            final Function<INPUT, KEY> keyFunction,
            final Consumer<INPUT> consumer); }
JCacheBasedConsumerMemoizer extends AbstractJCacheBasedMemoizer<KEY, INPUT> implements Consumer<INPUT> { @Override public void accept(final INPUT input) { final KEY key = keyFunction.apply(input); invoke(key, givenKey -> { consumer.accept(input); return input; }); } JCacheBasedConsumerMemoizer(
            final Cache<KEY, INPUT> cache,
            final Function<INPUT, KEY> keyFunction,
            final Consumer<INPUT> consumer); @Override void accept(final INPUT input); }
JCacheBasedConsumerMemoizer extends AbstractJCacheBasedMemoizer<KEY, INPUT> implements Consumer<INPUT> { @Override public void accept(final INPUT input) { final KEY key = keyFunction.apply(input); invoke(key, givenKey -> { consumer.accept(input); return input; }); } JCacheBasedConsumerMemoizer(
            final Cache<KEY, INPUT> cache,
            final Function<INPUT, KEY> keyFunction,
            final Consumer<INPUT> consumer); @Override void accept(final INPUT input);  }