How to cache an observable data in Angular 2 ?

devquora
devquora

Posted On: Feb 22, 2018

 

Caching of an observable data is done with the help of “observable.cache”. We can use caching in order to cache the response in the memory and then, on the next subscription, instead of requesting the remote server again. This operator is used at the end of the string. Caching is important for the performance, especially on bandwidth restricted devices and slow networks. You should have a good understanding of caching while working with promises but while translating it to observable, it is a bit difficult. Therefore, when interacting with observables, we typically set up a subscription on the consumer side and react to values coming through the pipe. We can easily add caching to the observables by adding publishReplay(1) and refCount.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Angular 2 Interview Questions

    What is Angular 2 ?

    Angular 2 is a completely revived component-based framework in which an application is a tree of loosely coupled compon..

    Angular 2 Interview Questions

    List some advantages of Angular 2 over Angular1.

    Angular 2 is a re-written version of Angular1 and not an update. The best way to compare Angular 2 and Angular 1 is by f..

    Angular 2 Interview Questions

    What are the new features of Angular 2?

    Angular 2 is a platform that encompasses a wide range of capabilities. Some new features were added in Angular 2 which i..