feat: Add a method to empty/flush Cached Views
Type: feat
Platform: all
I have an app that needs a login to see personal informations.
Since ionic beta 14 and the introduction of Cached Views I have big trouble when a user logoff and login with a different user.
The new user after the login still see the cached views of the previous user.
At the moment it seems that the only solution to avoid this is to disable everywhere the cached views ( $ionicConfigProvider.views.maxCache(0); ).
It would be very useful to have a ionic.flushCachedViews() method to clear all the cached views. I would call this when a user logoff.
Ok, sorry I just realised $ionicHistory.clearCache();.
But I'm not able to work with it.
When I try to use it strange things happen to my app.
I'm still playing with this. Very often when I try to use:
$ionicConfigProvider.views.maxCache(0);$ionicHistory.clearCache();cache: false,(insidetababstract state)
I have the following error:
0 874666 error Error: Attempted to assign to readonly property.
ChildScope@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:21459:42
$new@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:21467:40
compositeLinkFn@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:14866:38
compositeLinkFn@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:14890:24
nodeLinkFn@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:15526:35
compositeLinkFn@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:14887:23
publicLinkFn@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:14766:45
appendViewElement@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:47324:11
render@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:45864:58
init@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:45784:26
render@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:47225:18
register@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:47181:16
updateView@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:50834:31
http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:50811:21
$broadcast@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:22496:33
http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:39883:32
processQueue@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:20962:29
http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:20978:39
$eval@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:22178:28
$digest@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:21994:36
$apply@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:22282:31
done@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:17439:53
completeRequest@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:17629:15
requestLoaded@http://192.168.1.100:8100/lib/ionic/js/ionic.bundle.js:17570:24
@gio82 I encountered the same issue, but was able to disable cache with one of below 2 ways instead of entire app from $ionicConfigProvider. Thanks to @sreekanth on the ionic forum. http://forum.ionicframework.com/t/issues-w-routing-state-go/9418/15?u=acveer
Disable cache within state provider:
$stateProvider.state('myState', {
cache: false,
url : '/myUrl',
templateUrl : 'my-template.html'
})
Disable cache with an attribute: ion-view cache-view="false" view-title="Home">Home </ion-view
note: purposefully omitted '<' & '>' in the above HTML as the comment section is trying to render it.
Yeah, I ended up with the same solution but I consider this a turnaround. All my views are now not cached. :(
I hope and guess driftyco will work to fix these bugs.
Thanks @acveer for your help.
I really need something like this.
$ionicHistory.clearCache() should remove all cached views, this method doesn't touch in the previous view, this is unexpected in my opinion. I need a method to remove all the cached view's content programatically, would be very useful.
+1: Cached views are awesome, just need a way to clear them all on logout.
+1
clearCache should empty all the cached views, no matter where they stand or what is the parent state.
I will add some of my observations.
- Views with stateParams are cached without taking it into account ! That means a user page (that use the user ID as a parameter) would be cached, and displayed when trying to look at another user ! That's a big issue IMHO. Should I create a specific post for it ?
- Clearing one specific view should be possible using the view "name" attribute, if it exists.
- Controllers remains active in cached views. This should be wanted or not, so it should be a parameter to set, whether to pause them when cached or not.
Would someone be able to reproduce this error using the nightly build? Thanks
+1
Looks good to me. For me, the error no longer occurs.
@adamdbradley okay, I spent the day at reducing my project to get a mcve that could help you guys. I'm not sure I really succeeded in this, but I did reduced it enough to demonstrate some of the issues clearly. I modified the names and all this, but it's close to the actual structure of my real project. I think it's a common pattern - there is a list of events, in each event there is a list of users, and each user has its own page.
Codepen - http://codepen.io/JerryBels/pen/ogEdaK
Now, you can easily see some bugs here, if I'm not mistaken. First, when selecting a user, and then coming back and selecting another, it does display the first user's page. That shouldn't be the case since it uses stateParams. Note that the bug must be somewhat linked to the multiple nested states, since I failed to reproduce it on a simple states architecture (but I'm still very young with Angular so I will let you guys figure it out).
Second, when displaying the menu and switching event (clearing the cache happens there), the first time you do that it's the previous event that displays again (you can see its name in the menu). The next tries are good.
I think that's not everything but it's all I could get with this simplified example. I really hope it will help you guys.
Good luck ! :-)
+1
+100
$ionicHistory.clearCache() does not work
Forget my last comment, $ionicHistory.clearCache() does work in the beta 14, nightly 995
I don't think so. The bugs demonstrated in my codepen above still occurs. Lets say it does work sometimes.
+100 still present. tested with v1.0.0-rc.0-nightly-1122.
is a workaround available?
https://github.com/angular/angular.js/issues/9128
looks like the same bug
Sorry everyone, but I'm not being provided with an example of it not working. I just reviewed the codepen and clear cache is working when fired from $ionicView.enter event. I'll need a detailed codepen, and detailed description showing exactly how it's not working, and a full description of what elements should be removed.
@adamdbradley - in the codepen I provided ( http://codepen.io/JerryBels/pen/ogEdaK ) the first "switch event" doesn't work, the cache is not cleared, the same event shows up. I added a title for it to be more visible. This is a clearcache bug.
Besides, even if it's not a clearcache bug, it's a huge cache bug that when you get to a user page it doesn't take its id (which is a state parameter) into account, showing the page of the user who was first opened because that page is cached ! Should I create another thread for this issue to be taken into account ?
- App loads at
/#/app/guests - Click side menu toggle
- Click switch event button
- Clear clearCache should be called because welcomeCtrl entered
- Inspect the DOM, and .....
Details like this help me to debug. With you're app, please describe in detail how to see what you're seeing, and what I'm looking for.
Note: You're not using lifecycle events, so controller logic is only going to fire once, which is what you're seeing in your profileCtrl. But I think the biggest issue is that the app.profile state is set as an abstract state, which confuses the app and routing and a lot of its logic is skipped over.