Skip to content

Conversation

@khazzz
Copy link

@khazzz khazzz commented Aug 24, 2019

With this PR, one is able to cache a value of a Mono. Please see below a sample service that is caching a value of a Mono via Cacheable annotation:

@service
public class AemFacade {

private static final Logger LOGGER = LoggerFactory.getLogger(AemFacade.class);

private final WebClient webClient;

@Value("${environment.aemUrl}")
private String aemUrl;

@Autowired

public AemFacade(WebClient webClient) {
this.webClient = webClient;
}

@Cacheable(cacheNames = "media", key = "{ #request.id, #request.mediaType }")
public Mono<AemResponse> getMedia(AemRequest request) {
    
    LOGGER.debug("executing AemFacade.getMedias({},{}}", request.getId(), request.getMediaType());
    
    String url = aemUrl + buildResourceUri(request);
    
    return webClient

.get()
.uri(url)
.retrieve()
.bodyToMono(AemResponse.class)
.doOnError(this::handleThrowable)
.map(response -> failIfResponseHasErrors(request, response));
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant