In AngularJs, $http
has a very useful option of caching the result of a request to a specific url
.
For example:
$scope.getUsers = function () {
return $http.get('/users', {cache: true})
}
$scope.getUsers().then( response => console.log(response.data)); // Faz a requisição
$scope.getUsers().then( response => console.log(response.data)); // Pega o cache, pois foi feita uma primeira requisição
But now I have a small need: I would like to know when I get a response, whether that response came from a cache or not, and found nothing in the variable response
(which is returned in the then
parameter) index this.
Is there any way in AngularJS to do this?