Source:
<code>private CompletionStage<RestResponse> putValueToCache(RestRequest request) { String cacheName = request.variables().get("cacheName"); MediaType contentType = request.contentType(); MediaType keyContentType = request.keyContentType(); AdvancedCache<Object, Object> cache = restCacheManager.getCache(cacheName, keyContentType, contentType); Object key = request.variables().get("cacheKey"); if (key == null) throw new NoKeyException(); NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); if (request.method() == POST && cache.containsKey(key)) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.CONFLICT.code()).entity("An entry already exists").build()); } ContentSource contents = request.contents(); if (contents == null) throw new NoDataFoundException(); Long ttl = request.getTimeToLiveSecondsHeader(); Long idle = request.getMaxIdleTimeSecondsHeader(); byte[] data = request.contents().rawContent(); <START> return restCacheManager.getInternalEntry(cacheName, key, true, keyContentType, contentType).thenComposeAsync(entry -> { <END> if (entry instanceof InternalCacheEntry) { InternalCacheEntry ice = (InternalCacheEntry) entry; String etagNoneMatch = request.getEtagIfNoneMatchHeader(); if (etagNoneMatch != null) { String etag = calcETAG(ice.getValue()); if (etagNoneMatch.equals(etag)) { responseBuilder.status(HttpResponseStatus.NOT_MODIFIED.code()); return CompletableFuture.completedFuture(responseBuilder.build()); } } } return putInCache(responseBuilder, cache, key, data, ttl, idle); }); }</code><technical_language>code in is blocking, this thenCompose instead</technical_language>

Target:
private CompletionStage<RestResponse> putValueToCache(RestRequest request) { String cacheName = request.variables().get("cacheName"); MediaType contentType = request.contentType(); MediaType keyContentType = request.keyContentType(); AdvancedCache<Object, Object> cache = restCacheManager.getCache(cacheName, keyContentType, contentType); Object key = request.variables().get("cacheKey"); if (key == null) throw new NoKeyException(); NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); ContentSource contents = request.contents(); if (contents == null) throw new NoDataFoundException(); Long ttl = request.getTimeToLiveSecondsHeader(); Long idle = request.getMaxIdleTimeSecondsHeader(); byte[] data = request.contents().rawContent(); return restCacheManager.getInternalEntry(cacheName, key, true, keyContentType, contentType).thenCompose(entry -> { if (request.method() == POST && entry != null) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.CONFLICT.code()).entity("An entry already exists").build()); } if (entry instanceof InternalCacheEntry) { InternalCacheEntry ice = (InternalCacheEntry) entry; String etagNoneMatch = request.getEtagIfNoneMatchHeader(); if (etagNoneMatch != null) { String etag = calcETAG(ice.getValue()); if (etagNoneMatch.equals(etag)) { responseBuilder.status(HttpResponseStatus.NOT_MODIFIED.code()); return CompletableFuture.completedFuture(responseBuilder.build()); } } } return putInCache(responseBuilder, cache, key, data, ttl, idle); }); }