Search code examples
angularjscachingbrowser-cacheangularjs-servicecache-control

Chrome cache overriding angularjs disabling of cache


I am facing a peculiar issue wrt caching. I am using chrome currently I have angularjs service as below

var url = '/api/acts/' + accountId + '/policy/?filter=NEW_POLICY';
                return $http({
                    method : 'GET',
                    url : url,
                    cache : false,
                    headers: {'disableErrorRedirect': true,'Cache-Control' : 'no-cache'}
                });

Here i have set all attributes of not using the cache and always making a fresh call. But I have seen that 3 out of 5 times it is picking the same value. After sometime it automatically refreshes. Server side there is not caching issue as I am not caching it. In Chrome Dev tools, there is an option called Disable Cache and when i check it , the results are never cached and I get the latest results. I want to make sure that always refereshed data should be return despite of any settings on chrome. I am really confused how to handle this. As mentioned above, I have written all the angularjs and http code to avoid caching. Any help would be appreciated.


Solution

  • I had this same issue and resolved it by declaring the cache config globally. It's not ideal, but better than having to add a random string.

    angular.module('app', [])
      .config(function ($httpProvider) {
        $httpProvider.defaults.headers.common['Cache-Control'] = 'no-cache';
        $httpProvider.defaults.cache = false;
      });