Defining the caching requirement
As you have learned throughout the previous chapters, the HTTPClient
module is Observable-based, which means that methods such as get
, post
, put
, and delete
return an Observable. Subscribing multiple times to this Observable will cause the source Observable to be created repeatedly, hence performing a request on each subscription – as we learned in Chapter 9, Demystifying Multicasting, this means it is a cold Observable. This behavior will result in an overhead of HTTP requests, which may decrease the performance of your web applications, especially if the server takes some time to respond.
Reducing HTTP requests by caching the result on the client side is one of the most commonly used techniques to optimize web applications. Client-side caching involves storing previously requested data so that you don’t raise repetitive requests to the server and harm your application’s performance.
Let’s picture this with a streaming...