0

Is it possible to cache some http until parameters used in url change:

app.factory('dataService', function ($http,$rootScope) {
    return {
        getData: function () {
            return $http.get(rest.getData
           + $rootScope.number + "/" + $rootScope.blb
            ).then(function (result) {
                return result.data;
            });
        }
    }
});

So, when $rootScope.number changes in controller, I need to call http again, until then it should be cached. Is it possible and how?

2 Answers 2

1

Angular's $http has cache built in. Set cache as true in your $http request options:

$http.get(url, {cache: true}).then(...);
0

If you want to cache data you can do it in a number of ways.

You can cache it inside your service also.

  • Here is post which should help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.