Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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?

Edit: from a link in the comments this helps me explain things a bit clearer:

const observable = Observable.defer(
    () => actualFn().do(() => this.console.log('CACHE MISS', cacheKey))
  )
  .publishReplay(1, this.RECACHE_INTERVAL)
  .refCount().take(1)
  .do(() => this.console.log('CACHE HIT', cacheKey));

Putting the Observable into a const is okay for the "get all blog-posts" as it is always the same request.

But how do I do similar for a get blog-post with arbitrary identifier?

I've been considering putting the Observables into an array or tuple with the blog-post identifier as the key. But I'm not hugely experienced in this area so wanting to check that I'm not missing a way to go about it with the RxJS - either that or something completely obvious :0

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda