【发布时间】:2021-02-18 16:43:14
【问题描述】:
我正在尝试缓存由 webclient 调用返回的身份验证令牌响应。
public Mono<Token> getToken() {
return webclient.post().retrieve()
.bodyToMono(Token.class)
.cache(this::getTokenLiveDuration, t -> Duration.ZERO, () -> Duration.ZERO).log();
}
public Mono<MyResponse> execute() {
return getToken().flatMap(token -> {
webclient.post().header("Auth", token.getValue())
.retrieve()
.bodyToMono(MyResponse.class)
}
}
但是如果我在同一个实例中运行两次execute(),它们有不同的令牌,这意味着缓存不起作用。
.cache的正确使用方式或缓存webclient响应的正确方式是什么?
【问题讨论】:
标签: java spring-boot project-reactor spring-webclient