Hacker News new | ask | show | jobs
by crucialfelix 4304 days ago
With basic $http or resource:

You have to reload all the data each time you go to this view (if you navigate back to previous page it has to reload).

You have to reload data that is used on multiple pages. eg. products, categories, tags and especially user

The most common solution is to start stuffing things in $rootScope, after that you stuff it in localStorage using angular-cache (which is great).

My own system keeps the user's menu in cache, so it loads near instantly when they come back to the site (still logged in). It invalidates the cache if the user or app version has changed.

1 comments

For you specific purpose, I don't see why not using the built-in caching mechanism of Angular https://docs.angularjs.org/api/ng/service/$http#caching

The cool thing about angular-data, is that stuff it available, even when the browser is offline and you do a refresh.

the built in $http cache isn't at all suitable for what i described.

I do currently use angular-cache (from the author of angular-data) and build on top of that.

I specifically need to invalidate the storage if the user is different, the server generated session id is different or if the app version has changed since the last page load.

this is a service called UserStorage which can safely be used knowing that it gets dumped if somebody tries to mess with the user or they just logged out/in.

the site I built this for is not a single page app, people load pages often. persistence is essential.

the whole site appears to be server side personalized with menus, saved notes added to property listings etc. but its all frontend enhancement and the server can cache all the pages.