Java 如何使缓存的Mono无效?
有没有办法使缓存的Mono无效?是手动的还是有条件的 我的情况如下:Java 如何使缓存的Mono无效?,java,project-reactor,Java,Project Reactor,有没有办法使缓存的Mono无效?是手动的还是有条件的 我的情况如下: private Mono<String> cachedMono; public MyService() { this.cachedMono = cacheData() .cache(value -> Duration.ofHours(1), ex -> Duration.ZERO, () -> Duration.ZERO); } private Mono<String&g
private Mono<String> cachedMono;
public MyService() {
this.cachedMono = cacheData()
.cache(value -> Duration.ofHours(1), ex -> Duration.ZERO, () -> Duration.ZERO);
}
private Mono<String> cacheData() {
return webClient.get()
.uri("/api/data")
.retrieve()
.bodyToMono(String.class);
}
public Mono<String> retrieveData() {
return cachedMono;
}
找到了一个类似的链接,但这不是我要查找的内容。目前无法强制缓存信号无效。然而,正如菲尔·克莱所提到的,还有一个悬而未决的问题: 我们目前正在考虑扩大该操作符的作用域,可以提供一个谓词,也可以获得一个
一次性
来手动使缓存无效
public void dataHasBeenChangedNotification(String newData) {
// how to update cache with the new data?
// or at least force the cache to invalidate and not to wait 1 hour
}
虽然我们希望在3.4.x行中添加该功能,但这不会立即可用。您可能会感兴趣