use of org.apache.kafka.streams.query.KeyQuery in project kafka by apache.
the class CachingKeyValueStore method runKeyQuery.
@SuppressWarnings("unchecked")
private <R> QueryResult<R> runKeyQuery(final Query<R> query, final Position mergedPosition, final PositionBound positionBound, final QueryConfig config) {
QueryResult<R> result = null;
final KeyQuery<Bytes, byte[]> keyQuery = (KeyQuery<Bytes, byte[]>) query;
if (keyQuery.isSkipCache()) {
return wrapped().query(query, positionBound, config);
}
final Bytes key = keyQuery.getKey();
if (context.cache() != null) {
final LRUCacheEntry lruCacheEntry = context.cache().get(cacheName, key);
if (lruCacheEntry != null) {
final byte[] rawValue;
if (timestampedSchema && !WrappedStateStore.isTimestamped(wrapped())) {
rawValue = ValueAndTimestampDeserializer.rawValue(lruCacheEntry.value());
} else {
rawValue = lruCacheEntry.value();
}
result = (QueryResult<R>) QueryResult.forResult(rawValue);
}
}
// the merged position above
if (result == null) {
result = wrapped().query(query, PositionBound.unbounded(), config);
}
result.setPosition(mergedPosition);
return result;
}