0

This is really more of a question. I am using several http requests in my application that spans an entire site really.

  1. Is it better to cache the request or is there a more efficient manner to only make the request on given URL's?
  2. Am I understanding the cache method correctly (see below code)

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!

1 Answer 1

1
  1. 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?

  2. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

It does! I think really the cache is the solution I was looking for. I am a fan of elegant and simple. I think this is great! lol still just learning the insides and out of angularjs syntax.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.