- ChatGPT, what are key skills for Web devs in 2024?
ChatGPT: - Security and authorization!

How to cache HTTP requests in Angular

This is Angular Knowledge Pill - short and concise article! ๐Ÿ’Š
It takes just 10 seconds to learn something new ๐Ÿ”ฅ
Like taking your morning vitamins ๐Ÿ˜ƒ

Below code presents how to cache HTTP requests in Angular!
First, we just need to execute a regular HTTP query (for ex. get) and pipe the stream through shareReplay operator! This transforms the initial stream to a ReplaySubject! In other words, new subscriptions will NOT execute other HTTP requests but a cached value will be used. If you want to get the fresh value just create another HTTP stream without shareReplay operator and subscribe to it.

If you would like to receive this kind of knowledge pills directly into your mailbox, subscribe at the bottom of the page. I will be sending them regularly! Remember, it just takes 10 seconds to learn something new!

Subscribe to Dev Academy

Join over 6000 subscribers that receive latest knowledge and tips!

    By submitting this form you agree to receive emails with news, promotions and products and you accept Privacy Policy.