Jimmy
Jimmy

Reputation: 59

Falcor Model with Cache data from External Api

How will the json data sent over from external Api be cached into the Falcor-Model? Also, how to specify in the Model to hit the external Api again if data not present in the cache?

My doubt was partially answered in one of the posts: How does Falcor cache data in the server side?

So now I understand that Falcor-Model cache works only at the client side, which is fine. But how will the Model work if the data is not present in the cache?

var model = new falcor.Model({source: new falcor.HttpDataSource('http://localhost/rating.json') });
  model.
    get("rating").
    then(function(response) {
      document.getElementById('filmRating').innerText = JSON.stringify(response.json.rating,null, 4);
    });

Here the response is a json object, which can be put into a Falcor-Model cache and stored globally in the client side. But how can the Model be triggered again if data not present in cache?

Upvotes: 0

Views: 187

Answers (1)

Anup Bishnoi
Anup Bishnoi

Reputation: 412

The main advantage of using Falcor is that you should not have to care whether data is present in cache or fetched from the server, because model.get() which fetch all the data missing in the cache from the server by making an HTTP request.

So, the first model.get(path) query will fetch from server, and put response in cache. If you call model.get(path) again, it will be served from the cache.

Upvotes: 1

Related Questions