Ionic Clear Cache

Hi guys, I have a button that whenever i Logout and returns to Login View it clear all the cache… now I was facing a problem as I Login for the first time and Logout immediately, It doesn’t clear the cache of Login view and as I repeat to login again and logout… the function works now… What would be the best solution here?

.controller(‘LoungeCtrl’, function ($scope, $state, $ionicHistory, Data) {

$scope.logout = function () {
        $ionicHistory.clearCache();
        $ionicHistory.clearHistory();
        $state.go('index');
};

})