ThinkBonobo
ThinkBonobo

Reputation: 16515

Does Angular $http cache failed attempts?

I wasn't sure of this and didn't see the documentation on it. If I do a call as so...

...
return $http.get(baseUrl + '/lists/' + listObj.id, {cache: true})
    .then(function(resp){
          ...
          return null;
    }, function fail(err){
          return $q.reject(err);
    });

Angular would cache the http response and use that value next time I call the same http request. However, let say the connection fails or the list object id has since been created so the url now works. will will it have cached the failed attempt?

If it does do I have to manually dig into the $http.defaults.cache and remove it?

Upvotes: 0

Views: 430

Answers (1)

PSL
PSL

Reputation: 123739

You wouldn't need to. When cache enabled angular keeps the promise object with respect to the url in cache and any subsequent requests will receive the same promise so that the call to the server is not made again. But in case of unsuccessful calls the cache will get removed as the ajax call comes back from the sever. However if you make any more calls between that time you will eventually get the same failure for all those calls since they all have same promise.

Upvotes: 1

Related Questions