Live data from Hacker News

Angular-data: data store and caching for Angular.js

angular-data.pseudobry.com

41–49 of 49 posts

Re: Angular-data: data store and caching for Angular.js

#41
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

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.

Re: Angular-data: data store and caching for Angular.js

#42
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

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 kee…

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.

Re: Angular-data: data store and caching for Angular.js

#43
Hey pseudobry, thanks for the hard work first of all. I started using the 2.x branch on a large project and it saved me soooo much time and code over what I was trying to write around localStorage caching and expiration while trying to learn Angular at the same time.

I tried following the advice to upgrade to 3.x when it appeared on the API docs, but it broke my app completely which, after spending 5 minutes reading the 3.x branch's docs made complete sense - you're going for something much larger here.

I haven't personally played with Ember yet, but this seems like it might be inspired by Ember Data? Is that right? From what I hear, that's one of the many thing that Ember has gotten really right.

Thanks again!

Re: Angular-data: data store and caching for Angular.js

#44
post #17
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

Using $http and callbacks is great to get started but it doesn't scale up to large apps very well.

Can you explain why? A large app will not likely make a far greater number of http calls at the same time. If you must have up to date data then I don't see an alternative in something like angular.

Re: Angular-data: data store and caching for Angular.js

#45
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

For those writing largish non-trivial apps its essential to separate concerns for maintainability and testability. Controllers and UI logic get separated from domain logic and your Model layer. $scope is no Model layer.

[deleted]

Re: Angular-data: data store and caching for Angular.js

#46
post #14

"Before writing angular-data I used to create fleets of services for my various resources, each performing data management and communicating with a persistence layer." Can someone give me an example of this? I just use $http and populte the $scope models in callbacks so I don't really recognize the problem.

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 kee…

[deleted]

Re: Angular-data: data store and caching for Angular.js

#47
post #43

Hey pseudobry, thanks for the hard work first of all. I started using the 2.x branch on a large project and it saved me soooo much time and code over what I was trying to write around localStorage caching and expiration while trying to learn Angular at the same time. I tried following the advice to upgrade to 3.x when it appeared on the API docs, but it broke my app completely which, after spending 5 minutes reading…

I think you're confusing angular-cache with angular-data. Angular-cache (what you describe as 2.x and 3.x) is a drop-in replacement for $cacheFactory. It's a key-value store with extra caching goodies.

Angular-data (at 1.0.0-rc.1 right now) is a full-fledged data store and resource manager.

Re: Angular-data: data store and caching for Angular.js

#48
post #39

This looks interesting, but I'm not sure whether it's worth tying into a complex project using angular. I have found angular already has a large learning curve for new developers, and adding another layer with its own syntax on top of it adds some complexity that I'm not necessarily convinced that is good in that situation. It looks alright though in terms of what it offers on first inspection though. It does solve s…

As someone with a large angular project, this looks to me like it would reduce complexity if it works as well as it says on the tin. In my experience, it takes a ton of work and complexity to make working with data convenient and performant. I'm excited to try this out.

Re: Angular-data: data store and caching for Angular.js

#49
post #42

Earlier quoted context omitted.

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 kee…

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.

Post reply on HN