-
Notifications
You must be signed in to change notification settings - Fork 156
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
Caching promises doesn't work as expected #251
Comments
I think it might be that Angular.js 1.x changed the format of the $http response data that it saves to the cache. Ugh, angular-cache would have to change its behavior depending on which version of Angular is being used. |
I tried searching Angular docs for any documentation for that update but I didn't find any. |
Same here. Yep seems that response format was changed... |
Note that starting from 1.6, |
For our needs i'm just added wrapper around CacheFactory, to drop token headers from the cache. |
Facing the same issues here, using angular 1.6.7 1 - $http now does not have sucess() / error() methods anymore.
|
If you replace the CacheFactory for the angular $cacheFactory, and cache an array, the same problem does not happen. |
Investigating further, the reason it works with $cacheFactory for caching an array is simply the way angular uses the cached value. TL;DR
How it works under the hood, (angular 1.5.X and later)
If the cache do not have a cached value: If the cache has a cached value:
|
I've solved the issue passing the full Promise Object generated by the $http service to the cache. Angular will check fot the success of the Promise when resolving it on the resolvePromise() method of the $http service. (check code in the my comment above) With that approach your Promise content can be anything and angular will take care of properly using it (avoiding the isArray() check and using the cached value array as an Promise object).
|
Using Angular 1.5.8 and angular-cache 4.6
In my service:
In my localStorage the value is stored like this:
It's basically the same issue here #115 and here #143 but nothing fix it
The text was updated successfully, but these errors were encountered: