I’m trying to make an $http.get to retrieve a json, but it is always cached (except for the first call of course).
I’ve read several post about $ionicHistory.clearCache() and all the option in the ion-nav-view caching: http://ionicframework.com/docs/api/directive/ionNavView,
but I’m not able to find a solution.
According to my experience, if you put in the view lifecycle events of entering and leaving, it will trigger everytime and renew regardless of the cache.
First check if the method you are putting in is something that is only called once but you think it is called many times. For example, $scope.$on("$ionicView.loaded"), a method most of the time called once throughout the app lifecycle.
Second check the angular http service and you will find $http basic level method has a param to enable/disable the cache . Angular HTTP Service
I have the same problem in the moment.
I tried to set $http.defaults.cache to false or put it withing the http config like
$http.get('api/path',{
cache: false
}
But I will always get the same response. I checked with a browser and there I will get the updated content.
Maybe someone can help with the problem.
I only tested on Android.
I´m newbie in ionic and I get an error when I deploy the app to a device with android gingerbread. The problem doesn’t occur in the development environment (I mean using “ionic serve”).
After to add several log traces, I have seen that $http.get(url,config).success... is correctly invoked each time. However the request only is sent to the server the first time (I have debugged the server and it has confirmed my suspects). In this way the data is well refreshed only the first time.
I am having the same issue.
My first call brings the data from server but the same call gets response from cache every time i make the call after the first.
I.e. on pull to refresh
I’ve tried putting {cache:false} but it is not working.
Any clues on this?
I couldn’t find the solution so I wrote my own (I know it’s not the best solution and might need improvements)
Implemented an interceptor that appends the time-stamp on calls which are not for assets (html/css files etc.)
myApp.factory('httpInterceptor', ['$q',function($q) {
var regex = new RegExp('\.(html|js|css)$','i');
var isAsset = function(url){
return regex.test(url);
};
return {
// optional method
'request': function(config) {
// do something on success
if(!isAsset(config.url)){ //if the call is not for an asset file
config.url+= "?ts=" + Date.now(); //append the timestamp
}
return config;
},
// optional method
'requestError': function(rejection) {
// do something on error
return $q.reject(rejection);
},
// optional method
'response': function(response) {
// do something on success
return response;
},
// optional method
'responseError': function(rejection) {
return $q.reject(rejection);
}
};
}]);
//appended the interceptor in the config block using $httpProvider
// $httpProvider.interceptors.push('httpInterceptor');
I am having this issue as well and it is causing very serious consequences for me. If anyone has a solution please let me know, your help is greatly anticipated and appreciated.
Thank you, I did finally get that working for me, although I had to modify the regex so that it only applied to xml files. It was breaking image assets for me.
Still, this seems like a workaround. Why isn’t the $http call getting the updates naturally? Especially if explicitly disabling cache… Is this a bug that just hasn’t been fixed or am I misunderstanding the intended functionality?
Although not the best solution, as mentioned by you, it worked perfectly to “break” the cache $ http.get and update in real time the information in my App. Thank you.
In my own case, I used console.log and discovered that the results of the $http.get were not actually being cached but it was the page where I was using the data returned from the $http.get that was being cached.
so, basically, on the pages that were being cached, I had to add this inside the tag cache-view=“false”. Like so : and voila my problem is solved!