Home:ALL Converter>Remove cache after service call

Remove cache after service call

Ask Time:2015-12-15T20:39:11         Author:Micko

Json Formatter

So I have service with two methods. I am using built-in cache support for $resource. What i want to achieve is when i make some service call from controller to refresh cache. I was trying some example with $cacheResource but no success. Below is my code

Service

angular.module('module').factory('Service1',['$resource',
   function ($resource){
     return $resource('..api/latest/myservice', {}, {

       takeSomething: {
         method: 'GET',
         url: '..api/latest/myservice/takesomething',
        cache: true
       },

       putSomething: {
         method: 'GET',
         url: '..api/latest/myservice/putsomething',
         cache: true
       }

      }
}]

Controller

angular.module('module').factory('MyController',['$scope','Service1',
     function($scope, service1) {
       ....

     $scope.update = function() {
       service1.putSomething({
       ......
       refresh cache for takeSomething method in service or for all methods
     });
     }

}

So when i call this function update from controller i want to refresh cache for takeSomething methods or for all methods.

Author:Micko,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34289556/remove-cache-after-service-call
yy