Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Angular2 y RxJS: almacenamiento en caché de un servicio que toma un parámetro

Estoy tratando de agregar almacenamiento en caché a un servicio HTTP Angular2 y parece que no puedo resolverlo.

Seguí otras publicaciones y funciona perfectamente para servicios HTTP que no toman ningún parámetro, por ejemplo

 workSummaries = this.http.get('http://locahost:8080/teams') .map((response: Response) => response.json()) .publishReplay(1, 3000) .refCount() .take(1);

Sin embargo, estoy perdido tratando de averiguar si puedo hacer el trabajo anterior cuando introduzco un parámetro teamId que debe enviarse con la solicitud.

Entonces, idealmente, si se usó el mismo ID de equipo en los últimos X segundos, simplemente lea desde el caché; de lo contrario, si es un ID de equipo nuevo o si han pasado 3 segundos, llame al servicio.

Cualquier ayuda sería genial.

Gracias, Kevin.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar un Mapa para mantener la asociación de equipo/ID de equipo (no toqué la parte de creación Observable):

 summaries = new Map < number, Observable < Team >> (); getTeam(id: number) { if (!this.summaries.get(id)) { let team = this.http.get('http://locahost:8080/teams/' + id) .map((response: Response) => response.json()) .publishReplay(1, 3000) .refCount() .take(1); this.summaries.set(id, team) } return this.summaries.get(id); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!