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?

firstChild
  • 326
  • 2
  • 12

2 Answers2

1

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

$http.get(url, {cache: true}).then(...);
Rebornix
  • 5,272
  • 1
  • 23
  • 26
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.
Community
  • 1
  • 1
amitthk
  • 1,115
  • 1
  • 11
  • 19