0

I need you to clear the cache always. But when I create, update or delete a client, always get the same result. Only when I delete the cache manually (Ctrl+Shift+Supr) I can see the new data.

.factory('Clients', ['$resource', function ($resource) {
    return $resource(pathApi, {}, {
        query: {
            method: 'GET',
            isArray: false
        }
    });
}])

angular.module('app.controllers').controller('controller', ['$scope','Clients', function ($scope,  Clients) {

            Clients.get().$promise.then(
                //success
                function (value) {
                    $rootScope.clients= value;
                },
                //error. 
                function (error) {
                   alert(error);
                }
            );
  }]);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
DAVINCHI
  • 21
  • 7
  • Isn't there a `cache` property that you can pass in as config. – PSL Aug 20 '14 at 15:00
  • Something like this? .factory('Clients', ['$resource', function ($resource) { return $resource(pathApi, {}, { query: { method: 'GET', isArray: false, cache: false } }); }]) – DAVINCHI Aug 20 '14 at 15:14

2 Answers2

1

This seems to work for me:

app.run(function($rootScope,$templateCache) {
  $rootScope.$on('$viewContentLoaded', function() {
    $templateCache.removeAll();
  });
});
Rob
  • 1,840
  • 2
  • 12
  • 19
1

Here is the solution. Add a time variable to the request: params: { 'foobar': new Date().getTime() }

.factory('Clients', ['$resource', function ($resource) {
    return $resource(pathApi, {}, {
        query: {
            method: 'GET',
            isArray: false,
            params: { 'foobar': new Date().getTime() }
        }
    });
}])
Community
  • 1
  • 1
DAVINCHI
  • 21
  • 7