Source:
<code>CompletionStage<RestResponse> putValueToCache(RestRequest request) { String cacheName = request.variables().get("cacheName"); MediaType contentType = request.contentType(); MediaType keyContentType = request.keyContentType(); RestCacheManager<Object> restCacheManager = invocationHelper.getRestCacheManager(); AdvancedCache<Object, Object> cache = restCacheManager.getCache(cacheName, keyContentType, contentType, request); Object key = request.variables().get("cacheKey"); if (key == null) throw new NoKeyException(); NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder().status(HttpResponseStatus.NO_CONTENT); 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.getPrivilegedInternalEntry(cache, key, true).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()); } } } <START> return putInCache(responseBuilder, cache, key, data, ttl, idle, request.getSubject()); <END> }); }</code><technical_language>No, this is wrong: cache object passed in Subject applied (cache.withSubject(subject)) (RestCacheManager this)</technical_language>

Target:
CompletionStage<RestResponse> putValueToCache(RestRequest request) { String cacheName = request.variables().get("cacheName"); MediaType contentType = request.contentType(); MediaType keyContentType = request.keyContentType(); RestCacheManager<Object> restCacheManager = invocationHelper.getRestCacheManager(); AdvancedCache<Object, Object> cache = restCacheManager.getCache(cacheName, keyContentType, contentType, request); Object key = request.variables().get("cacheKey"); if (key == null) throw new NoKeyException(); NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder().status(HttpResponseStatus.NO_CONTENT); 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.getPrivilegedInternalEntry(cache, key, true).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); }); }