Simple XHR Request

Code

      
        angular.module('myAwesomeApp', ['angular-promise-cache'])
          .controller('simpleXHRRequestCtrl', function($scope, $http, promiseCache) {
            var ttl = 5000;

            function makeXhrRequest() {
              return $http.get('example-data.json');
            }

            $scope.send = function() {
              promiseCache({
                promise: makeXhrRequest,
                ttl: ttl,
                // New in v0.0.5!
                localStorageEnabled: true
              });
            };
          });
      
    

Output

Number of HTTP requests: {{ numberOfHttpRequests }}
Number of resolved promises: {{ numberOfResolvedPromises }}
Expiration time of cached promise (in ms): {{ expirationTime }}

Actions