Skip to content

rxjs 7: Redo requests after a certain time / cache expiration #6264

Answered by josepot
StefanKern asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @StefanKern

One thing that can be a bit surprising about shareReplay with refCount is that if the the source completes, then that's it: the resulting observable will never re-subscribe to the source, and every time that a new subscriber comes: it will replay the latest value(s) and then complete. I once opened an issue because I thought that was a bug 😅.

So, since your source is an Observable that emits once and then it completes, then I would suggest enhancing it so that it doesn't complete, i.e: concat(source, NEVER)

Ok, sure, but then how do we make sure that the cached value stays alive for a certain amount of time 🤔?

I suggest using a pipeable operator like this:

import { Observable,

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@josepot
Comment options

@josepot
Comment options

@StefanKern
Comment options

@josepot
Comment options

@josepot
Comment options

Answer selected by StefanKern
Comment options

You must be logged in to vote
1 reply
@StefanKern
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants