Source:
<code>public Sequence<T> run(QueryPlus<T> queryPlus, ResponseContext responseContext) { Query<T> query = queryPlus.getQuery(); final CacheStrategy strategy = toolChest.getCacheStrategy(query); final boolean populateCache = CacheUtil.populateCacheOnDataNodes(query, strategy, cacheConfig); final boolean useCache = CacheUtil.useCacheOnDataNodes(query, strategy, cacheConfig); final Cache.NamedKey key; if (strategy != null && (useCache || populateCache)) { key = CacheUtil.computeSegmentCacheKey( cacheId, segmentDescriptor, strategy.computeCacheKey(query) ); } else { key = null; } if (useCache) { <START> close(); <END> final Function cacheFn = strategy.pullFromSegmentLevelCache(); final byte[] cachedResult = cache.get(key); if (cachedResult != null) { final TypeReference cacheObjectClazz = strategy.getCacheObjectClazz(); return Sequences.map( new BaseSequence<>( new BaseSequence.IteratorMaker<T, Iterator<T>>() { @Override public Iterator<T> make() { try { if (cachedResult.length == 0) { return Collections.emptyIterator(); } return mapper.readValues( mapper.getFactory().createParser(cachedResult), cacheObjectClazz ); } catch (IOException e) { throw new RuntimeException(e); } } @Override public void cleanup(Iterator<T> iterFromMake) { } } ), cacheFn ); } } if (populateCache) { final Function cacheFn = strategy.prepareForSegmentLevelCache(); return cachePopulator.wrap(base.run(queryPlus, responseContext), value -> cacheFn.apply(value), cache, key); } else { return base.run(queryPlus, responseContext); } }</code><technical_language>I tell, this of if (cachedResult != null) part of logic ensure cache contains value, else decrement counter potentially incorrectly base sequence runs</technical_language>

Target:
public Sequence<T> run(QueryPlus<T> queryPlus, ResponseContext responseContext) { Query<T> query = queryPlus.getQuery(); final CacheStrategy strategy = toolChest.getCacheStrategy(query); final boolean populateCache = CacheUtil.populateCacheOnDataNodes(query, strategy, cacheConfig); final boolean useCache = CacheUtil.useCacheOnDataNodes(query, strategy, cacheConfig); final Cache.NamedKey key; if (strategy != null && (useCache || populateCache)) { key = CacheUtil.computeSegmentCacheKey( cacheId, segmentDescriptor, strategy.computeCacheKey(query) ); } else { key = null; } if (useCache) { final Function cacheFn = strategy.pullFromSegmentLevelCache(); final byte[] cachedResult = cache.get(key); if (cachedResult != null) { final TypeReference cacheObjectClazz = strategy.getCacheObjectClazz(); return Sequences.map( new BaseSequence<>( new BaseSequence.IteratorMaker<T, Iterator<T>>() { @Override public Iterator<T> make() { try { if (cachedResult.length == 0) { return Collections.emptyIterator(); } return mapper.readValues( mapper.getFactory().createParser(cachedResult), cacheObjectClazz ); } catch (IOException e) { throw new RuntimeException(e); } } @Override public void cleanup(Iterator<T> iterFromMake) { } } ), cacheFn ); } } if (populateCache) { final Function cacheFn = strategy.prepareForSegmentLevelCache(); return cachePopulator.wrap(base.run(queryPlus, responseContext), value -> cacheFn.apply(value), cache, key); } else { return base.run(queryPlus, responseContext); } }