Highlighting the use cases of caching streams
The first use case is optimizing the HTTP requests in order to enhance the performance of our web applications. All that you have to do is put the result in a cache that is a shared place for all the consumers. This is what we did in the previous section.
There is another use case where caching streams makes a lot of sense: when accounting for expensive side effects on the streams. In general, we call the actions that we perform after a value is emitted side effects. This could be logging, displaying messages, doing a kind of mapping, and so on. Here's an example of a side effect using the tap
operator:
import {map, from } from 'rxjs'; import { tap } from 'rxjs/operators'; const stream$ = from([1, 2, 'Hello', 5]); stream$ .pipe( tap((value) => console.log(value)), map((element) => { if (isNaN(element...