Ionic cache and history clean issue


#1

Good day everyone!
I have a such application route structure:

.state('app', {
	url: "/app",
	abstract: true,
	templateUrl: "js/app.html"
})

.state('login', {
	url: "/login",
	cache: false,
	templateUrl: "js/login/login.html"
})

.state('app.tasks', {
	url: "/tasks",
	abstract: true,
	cache: true,
	views: {
		'mainContent': {
			templateUrl: "js/tasks/tasks.html"
		}
	}
})

.state('app.tasks.list', {
	url: "/list",
	cache: true,
	views: {
		'tasksListTab': {
			templateUrl: "js/tasks/tasks_list.html"
		}
	}
})

As u can see i have 2 abstract bases: login and app. The problem occurs with ionic cache…

  • So, when user logs in my app, he gets app.tasks.list page.
  • Ionic caches it.
  • User presses logout button.
  • User is redirected to login page, where $ionicHistory.clearHistory(); and $ionicHistory.clearCache(); executes.
  • User logs in one more time with other login/pass and get cached app.tasks.list page.

Any ideas why he gets cached page and what to do? The most interesting is that cache is not dropped only for page from where user logged out.

Thanks in advance!!


clearCache() possible bug?
#2

I am facing the same issue.
My only solution so far is to set cache:false on all the states.


#3

The problem is that ionic does not clear cache for the last view. The workaround is to clear cache on $ionicView.enter event:

$scope.$on("$ionicView.enter", function(scopes, states){
    $ionicHistory.clearHistory();
    $ionicHistory.clearCache();
});

Why this is working? I dont know…


#4

What page should i place these codes? Because when trying put them to login controller, i get some weird issues each time login/logout on mobile device.


#5

Solved with

$ionicHistory.nextViewOptions({
disableAnimate: true,
disableBack: true,
historyRoot: true
});