-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redo requests after a certain time / cache expiration #6260
Comments
@cartant I cannot follow your comment. Tried setting refCount to true, and then it does the request each time. Was it intended more as an internal comment? PS: seems like I exceeded the limit for calling the github api with HelloWorld. Had to change the searchstring... |
I left the terse comment because it appeared to be a straightforward Looking at it more closely, I suspect that the behaviour upon which you are relying is a bug - see #5696 - as it makes no sense. Once a subject errors or completes, that's supposed to be it; the subject should not forward additional notifications it might receive from any source to which it is subscribed. And Working as intended, AFAICT. A bug fix is pretty much always someone else's breaking change, I guess. |
I see, hmm but I'm kinda relaying on this functionallity. Is there a way to get the same behaviour with other functions? To me, the usecase seems quite reasonable :) |
I don't have time, ATM. Ask on SO - or in discussions in this repo or both - and reference the original SO answer and my comment above. It's definitely relying on a bug, IMO, so I'm closing this. |
@StefanKern I updated the answer at https://stackoverflow.com/questions/54947878/temporarily-caching-http-responses-from-parametrised-requests-using-rxjs-and-an/54957061#54957061 and posted a different solution for RxJS 7.0+ |
Missing feature in rxjs 7
In rxjs v7
publishReplay
,refCount
, etc where deprecated andshare
andshareReplay
are now the 'only' options when wanting use the result of an observable in multiple parts of the code, without redoing the complete 'observable'. An example for this is an API call, where the result is used in two places of the application, but you don't want to hit the network each time.This was usually done with
publishReplay
andrefCount
. If you wanted to limit the time these requests where valid, you could set awindowTime
inpublishReplay
and after "X"ms, the request repeated. (you also had to add atake(1)
at the end, but that would be another question/issue). This solution was taken from SO: https://stackoverflow.com/a/54957061With
share
orshareReplay
, you cannot reproduce the same behaviour.You can pass a windowTime to
shareReplay
, however after the time is exceeded, no more values are emitted at all!Example how it was working before:
rxjs: 6.6.3
Stackblitz: https://stackblitz.com/edit/angular-ivy-tyrbdw?file=src%2Fapp%2Fapp.component.ts
Result:
Example with shareReplay
rxjs": "^7.0.0-rc.2
Stackblitz: https://stackblitz.com/edit/angular-ivy-ggkvpw?file=src%2Fapp%2Fapp.component.ts
Result;
Note how the Observable doesn't emit anything anymore, after 5sec.
Expected behaviour:
Requests are repeated once the windowTime is exceeded.
The text was updated successfully, but these errors were encountered: