Reputation: 506
This is really more of a question. I am using several http requests in my application that spans an entire site really.
homeApp.controller('mainMenu', function($scope, $http) {
$http.get("http://localhost:3000/wp-json/menus/2", {
cache: true
}).then(function(response) {
$scope.menuData.data = response.data.items;
});
});
I am trying to keep this thing as quick and agile as possible. Thanks all!
Upvotes: 0
Views: 240
Reputation: 1751
You could probably customise the HTTP provider to look for certain paths and cache them for your application. But I think coding the specific calls you want cached by specifying cache=true
is better and clearer?
I think you have understood it correctly.
https://docs.angularjs.org/api/ng/service/$http
"When caching is enabled, $http stores the response from the server using the relevant cache object. The next time the same request is made, the response is returned from the cache without sending a request to the server."
So if you repeatedly make requests to /wp-json/menus/2
within the scope of an instance of your angular SPA, it will not hit the server. Its quite efficient.
I hope this helps.
Upvotes: 1