This is the accompanying article for my latest Egghead video lesson on caching data in Angular by leveraging RxjS.
Caching is hard, it's one of the hard topics in software development because so many things can go wrong. Even though some implementations are quite easily doable, the problem usually lies in when to invalidate the cache to not show stale data to the user and debugging issues (because you might run into your cache and not see what you'd actually expect). We've been all there, and still, often we need to cache data to improve the performance of our apps. Things I'm always considering there is...
- to delay the caching at the very latest moment. Try other optimizations before, and in case add in caching later
- consider server-side API level caching, whether that is response headers or cache servers like Redis. Note that the API is the single entry point where you have the best knowledge about data freshness.
Have 2 minutes? Head over to my site for the Egghead video lesson and a runnable Stackblitz. Read more »