Improve fix of duplicate upstream subscription during reactive cache put
This commit fixes an issue where a Cacheable method which returns a
Flux (or multi-value publisher) will be invoked once, but the returned
publisher is actually subscribed twice.
The previous fix 988f3630c would cause the cached elements to depend on
the first usage pattern / request pattern, which is likely to be too
confusing to users. This fix reintroduces the notion of exhausting the
original Flux by having a second subscriber dedicated to that, but uses
`refCount(2)` to ensure that the original `Flux` returned by the cached
method is still only subscribed once.
Closes gh-32370
@ -1037,45 +1036,34 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
@@ -1037,45 +1036,34 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
// Note: we don't use doFinally as we want to propagate the signal after cache put, not before
CachePutRequestr=this.request.get();
if(this.request.compareAndSet(r,null)){
r.performCachePut(this.cacheValue);
}
publicvoidonError(Throwablet){
this.cacheValue.clear();
}
@Override
publicvoiddoOnError(Throwableerror){
if(this.request.getAndSet(null)!=null){
this.cacheValue.clear();
}
publicvoidonComplete(){
this.request.performCachePut(this.cacheValue);
}
}
@ -1159,8 +1147,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
@@ -1159,8 +1147,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker