Local storage vs AngularJS $cacheFactory

Rasalom picture Rasalom · Oct 10, 2013 · Viewed 73.5k times · Source

I have a problem of storing a lot of client-side data, and I can't decide which way is better. Now I'm using AngularJS's cacheFactory, it works fine, but all data reloads with a new session. Is it worth to use local storage instead?

Answer

Blackhole picture Blackhole · Oct 10, 2013

If your goal is to store client-side and persistent data, you can't use the $cacheFactory, which just caches the data for the current session.

One solution is to use the new local storage API. This awesome Angular module makes all the dirty job for you, and even falls back to cookies for old browsers!