@Test void frequentlyAccessedEntriesShouldBePreservedByEviction() throws Exception { when(wrappedTextExtractor.extractContent(any(), any())) .thenReturn(_2MiB_RESULT); IntStream.range(0, 10) .mapToObj(STREAM_GENERATOR::apply) .peek(Throwing.consumer(any -> textExtractor.extractContent(STREAM_GENERATOR.apply(0), CONTENT_TYPE))) .forEach(Throwing.consumer(inputStream -> textExtractor.extractContent(inputStream, CONTENT_TYPE))); reset(wrappedTextExtractor); textExtractor.extractContent(STREAM_GENERATOR.apply(0), CONTENT_TYPE); verifyZeroInteractions(wrappedTextExtractor); }
@Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { byte[] bytes = IOUtils.toByteArray(inputStream); String key = Hashing.sha256().hashBytes(bytes).toString(); try { return cache.get(key, () -> retrieveAndUpdateWeight(bytes, contentType)); } catch (ExecutionException | UncheckedExecutionException e) { throw unwrap(e); } }
CachingTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { byte[] bytes = IOUtils.toByteArray(inputStream); String key = Hashing.sha256().hashBytes(bytes).toString(); try { return cache.get(key, () -> retrieveAndUpdateWeight(bytes, contentType)); } catch (ExecutionException | UncheckedExecutionException e) { throw unwrap(e); } } }
CachingTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { byte[] bytes = IOUtils.toByteArray(inputStream); String key = Hashing.sha256().hashBytes(bytes).toString(); try { return cache.get(key, () -> retrieveAndUpdateWeight(bytes, contentType)); } catch (ExecutionException | UncheckedExecutionException e) { throw unwrap(e); } } CachingTextExtractor(TextExtractor underlying, Duration cacheEvictionPeriod, Long cacheWeightInBytes,
                                MetricFactory metricFactory, GaugeRegistry gaugeRegistry); }
CachingTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { byte[] bytes = IOUtils.toByteArray(inputStream); String key = Hashing.sha256().hashBytes(bytes).toString(); try { return cache.get(key, () -> retrieveAndUpdateWeight(bytes, contentType)); } catch (ExecutionException | UncheckedExecutionException e) { throw unwrap(e); } } CachingTextExtractor(TextExtractor underlying, Duration cacheEvictionPeriod, Long cacheWeightInBytes,
                                MetricFactory metricFactory, GaugeRegistry gaugeRegistry); void recordStats(GaugeRegistry gaugeRegistry); @Override ParsedContent extractContent(InputStream inputStream, ContentType contentType); }
CachingTextExtractor implements TextExtractor { @Override public ParsedContent extractContent(InputStream inputStream, ContentType contentType) throws Exception { byte[] bytes = IOUtils.toByteArray(inputStream); String key = Hashing.sha256().hashBytes(bytes).toString(); try { return cache.get(key, () -> retrieveAndUpdateWeight(bytes, contentType)); } catch (ExecutionException | UncheckedExecutionException e) { throw unwrap(e); } } CachingTextExtractor(TextExtractor underlying, Duration cacheEvictionPeriod, Long cacheWeightInBytes,
                                MetricFactory metricFactory, GaugeRegistry gaugeRegistry); void recordStats(GaugeRegistry gaugeRegistry); @Override ParsedContent extractContent(InputStream inputStream, ContentType contentType);  }