O'Reilly logo

AngularJS Services by Jim Lavin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Caching data to reduce network traffic

One of the big issues with using external data services is finding ways to cache data on the client to reduce the number of network calls made during the lifetime of the application. AngularJS actually provides a service that allows you to cache objects on the client. The $cacheFactory service provides you with the ability to set up a named cache on the client that allows you to save data on the client using named value pairs.

You can provide some simple caching to your data services using the $cacheFactory service. What you'll need to do in your service is get a reference to the cache instance and then check it prior to making a call to the mongolab service. When you create a new object in the collection, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required