Caching RxJS HTTP responses

I’m using RxJS (via Angular2) to retrieve blog-posts from the WordPress REST API.

I’ve implemented caching on the Observable for “get all blog-posts” (i.e. blog list) via the example outlined here and everything is working great:

http://www.syntaxsuccess.com/viewarticle/caching-with-rxjs-observables-in-angular-2.0

But I’m a little stuck when it comes to retrieving/caching individual blog-posts.

Currently a fresh request is sent to “get blog-post by slug” whenever a blog-post is needed – no caching here and I would like to add some.

What I’m struggling with is – the above works fine for an individual GET for all posts. There’s only ever going to be 1 Observable here.

But I’m not sure how to implement it for an arbitrary number of Observables related to getting individual posts.

Are there any ideas on how to best go about this?

Read more here: Caching RxJS HTTP responses

Leave a Reply

Your email address will not be published. Required fields are marked *