DirtyMind
DirtyMind

Reputation: 2563

How to use 'cache: true' in angular for the given rest call?

I have never used cache in angular app. i am trying to use it. As given in the answer for the following question Stackoverflow Question

I want to use {cache:true} in below rest calls? How could i use it ? Do i need to add any dependency

getBusinessUnits: function (e) {
              return $resource($rootScope.REST_URL + '/option/businessUnits')
                       .query().$promise;
            },
            getAllLegalEntities: function () {
              return $resource($rootScope.REST_URL + '/option/allLegalEntities')
                       .query().$promise;
            },

Upvotes: 1

Views: 142

Answers (1)

dfsq
dfsq

Reputation: 193261

You will need to redefine query action of the constructed resource object and add cache settings:

getBusinessUnits: function (e) {
  return $resource($rootScope.REST_URL + '/option/businessUnits', null, {
    query: {method:'GET', isArray:true, cache: true}
  }).query().$promise;
}

Upvotes: 1

Related Questions