jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

View not being update with angular-cache with localStorage #181

Closed danielcha closed 9 years ago

danielcha commented 9 years ago

I'm building an Ionic app the uses angular-cache to leverage data persistence. This data is displayed in a ng-repeat list. Either by user interaction (in another view!) or new data being loaded in the background, I need the view to update to reflect this.

When developing my app everything works perfectly, however, as soon as I start using angular-cache with localStorage, views stop being updated. When I turn off localStorage (but still use in memory caching from angular-cache) everything works as expected: the data updates and so is the DOM.

I was able to reproduce the issue with this CodePen http://codepen.io/anon/pen/qdayMW. To demonstrate the issue you switch tabs (from home to about). If you look in the console you can see that new items are being added to the localStorage cache. However the homescreen doesn't update. If you then refresh the page (within the 10 second cache magAge) the page shows the correct list of items...

However, if we comment out line 81, the caching is no longer persistent after a refresh, however the new items are added to the DOM every time the view changes.

Note: I also posted this issue to the Ionic forum as I'm not sure which exactly is the root of the problem: http://forum.ionicframework.com/t/view-not-being-update-with-angular-cache-with-localstorage/25236

jmdobry commented 9 years ago

This must be something weird with ionic. I've been playing with your codepen, and as I click between the home and about tabs, the home controller code is only executed once at the very beginning, so while more items are being added to the cache, the resolve code that would get the latest items isn't run again.

jmdobry commented 9 years ago

The latest ionic implemented view caching (which is causing your "bug"), which you have to disable: http://ionicframework.com/docs/nightly/api/directive/ionNavView/