smallrye-mutiny: Provide the possibility to invalidate a cached Uni
Hello Mutiny team,
it would be great if an Uni created by Uni.cache() could be invalidated to cause a resubscription on the original Uni.
I can imagine an overloaded version Uni.cache(Predicate<T> isValid) that is called on every subscription on the cached Uni and as soon as it gets false the cached item is thrown away in favour to compute a new one.
Thank you and keep on making our JVM world reactive 🚀
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (12 by maintainers)
Done in #312, superseded by #313
@heubeck I pushed an early sketch / draft in #313
It provides
cacheUntil(BooleanSupplier)andcacheFor(Duration).Note that in this design invalidation is checked on new subscriptions, it looks quite sane to reason about IMHO. If we start also checking when and item or failure is ready to be propagated downstream then we may have starvation / infinite loops, especially in the
cacheUntilcase if the condition changes on the same thread.@heubeck I’m still willing to explore and see if we can come up with a good solution here. Right now
cache()provides us with memoization. Supporting invalidation (like a Clojure library does) is a good investigation area.@jponge I have not found a use for it yet, but remember that so far we have not progressed much beyond just writing simple test cases for HR.
I’ve kept your PR open as draft for reference @heubeck
I’ve been exploring some designs with
synchronizedblocks but it’s not great (but apparently correct). I’m going to have a look at drain loops and see if we can make it work this way.Thinking out loud. On the other hand I’m wondering if we are not trying to ask too much for what
Unican do. AUnirepresents an operation, and caching a result is perhaps something that should be done as part of an application business logic rather than inUniitself. Invalidation can quickly become complex, and there are good libraries for that (e.g., https://github.com/ben-manes/caffeine).Looking into it, there is indeed an opportunity to explore another design. It’s a more complex state machine if re-subscription happens. It’s on my radar.
I like the idea of having a cache group.
asLongshould beatMostto be homogeneous and receive a Duration.We could still keep the current cache method which would redirect on cache().indefinitely().
Le sam. 1 août 2020 à 00:21, Florian Heubeck notifications@github.com a écrit :
Already thought about doing this - hope to free some time.
Have a good time and thank you @jponge .
@heubeck we’re more or less all in vacations or going to vacations, so don’t be surprised to not hear back anything for the next 2-3 weeks.
Meanwhile if you have time and fancy looking at what’s under the cover, feel-free to hack and possibly open a pull-request 😉
Interesting