Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q - Reading from the server, and also from the cache - apply same mechanisme for basic $http #87

Open
thim81 opened this issue Apr 28, 2016 · 0 comments

Comments

@thim81
Copy link

thim81 commented Apr 28, 2016

I really like the approach of "Reading from the server, and also from the cache"

The first time this module downloads (or saves) any resource, it will cache a copy of that resource in your browser. That means that the next time you try and load the resource, the $promise will immediately resolve (and, in the code snippet above, you'll see the alert with the title of the post right away). This should provide you with a nice speed boost.

The module will, however, still make a request against the server endpoint. When it receives a response, it will update the cache entry with the new values, and it will also update the value of otherPost in place. It will also trigger a $digest, so that angular can update its views if there are any that use that data. Magic! (Finally, if you need to listen specifically for the completed HTTP request, you can use the $httpPromise on the resource object instead of the regular $promise object.)

We have build several Angular apps where we grouped all interactions with REST points in "services" and we use the basic $http.get() to get data with promises.

It's not so simple to switch to the "resource" way of working to be able to plug your "angular-cached-resource" in.

Have you come across similar angular plugins that support this "Reading from the server, and also from the cache" approach but then for the basic $http?

Or is there a way that we can implement your logic in our services without converting them all to the Resource method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant