如何将从外部Api发送的json数据缓存到Falcor模型中?此外,如果缓存中没有数据,如何在模型中指定再次命中外部Api?
我的怀疑在其中一篇文章中得到了部分回答:How does Falcor cache data in the server side?
所以现在我知道Falcor模型缓存只在客户端工作,这很好。但是,如果缓存中没有数据,那么模型将如何工作?
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);
});这里的响应是一个json对象,它可以放入Falcor模型缓存并全局存储在客户端。但是,如果缓存中没有数据,如何再次触发模型?
发布于 2018-02-26 21:41:47
使用Falcor的主要优点是您不必关心数据是存在于缓存中还是从服务器中获取,因为model.get()通过发出HTTP请求从服务器获取缓存中丢失的所有数据。
因此,第一个model.get(path)查询将从服务器获取,并将响应放在缓存中。如果您再次调用model.get(path),它将从缓存中得到服务。
https://stackoverflow.com/questions/45797683
复制相似问题