简体   繁体   English

具有来自外部Api的缓存数据的Falcor模型

[英]Falcor Model with Cache data from External Api

How will the json data sent over from external Api be cached into the Falcor-Model? 从外部Api发送过来的json数据将如何缓存到Falcor-Model中? Also, how to specify in the Model to hit the external Api again if data not present in the cache? 另外,如果在缓存中不存在数据,如何在模型中指定再次命中外部Api?

My doubt was partially answered in one of the posts: How does Falcor cache data in the server side? 我的疑问在其中一篇文章中得到了部分回答: Falcor如何在服务器端缓存数据?

So now I understand that Falcor-Model cache works only at the client side, which is fine. 因此,现在我了解到Falcor-Model缓存仅在客户端起作用,这很好。 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. 这里的响应是一个json对象,可以将其放入Falcor-Model缓存中,并全局存储在客户端中。 But how can the Model be triggered again if data not present in cache? 但是,如果缓存中不存在数据,如何再次触发模型?

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. 使用Falcor的主要优点是您不必关心数据是存在于缓存中还是从服务器获取,因为model.get()通过发出HTTP请求从服务器获取缓存中缺少的所有数据。

So, the first model.get(path) query will fetch from server, and put response in cache. 因此,第一个model.get(path)查询将从服务器获取,并将响应放入缓存中。 If you call model.get(path) again, it will be served from the cache. 如果再次调用model.get(path) ,它将从缓存中提供。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM