【发布时间】:2019-07-13 05:23:31
【问题描述】:
当我请求包含嵌套引用的路由时,我发现 Falcor 客户端出现问题。
这是一个例子:
考虑以下来自 Falcor 服务器在 model.get 调用上的 JsonGraph 响应
{
"todos": {
"0": { "$type": "ref", "value": ["todosById", "id_0"] },
"1": { "$type": "ref", "value": ["todosById", "id_1"] },
"length": 2
},
"todosById": {
"id_0": {
"name": "get milk",
"label": { "$type": "ref", "value": ["labelsById", "lbl_0"] },
"completed": false
},
"id_1": {
"name": "do the laundry",
"label": { "$type": "ref", "value": ["labelsById", "lbl_1"] },
"completed": false
}
},
"labelsById": {
"lbl_0": { "name": "groceries" },
"lbl_1": { "name": "home" }
}
}
当我使用以下路径调用model.get 时,以上所有 jsonGraph 结果都应该在缓存中:
model.get(['todos', {from: 0, to: 1}, ['completed', 'label', 'name']])
但是,手动访问缓存,我可以看到todos 和todosById 在缓存中,但不是labelsById。
我不确定,但看起来 labelsById 不在缓存中,因为它是二级引用?
我在这里遗漏了什么还是 Falcor 缓存的预期行为?
有什么办法可以强制labelsById 在缓存中,因此不会发出额外的数据源请求?
感谢任何帮助!
这个问题可以在这个小项目中重现: https://github.com/ardeois/falcor-nested-references-cache-issue
更新
感谢@james-conkling 的回答,可以通过执行以下model.get 来缓存json 图:
model.get(
['todos', {from: 0, to: 1}, ['completed', 'name']],
['todos', {from: 0, to: 1}, 'label', 'name']
);
但是,在服务器端 Falcor 路由器将调用 todos[{integers:indices}] 路由两次。这可能会对您的 Falcor 服务器的 API 或数据库调用产生影响。
【问题讨论】:
标签: falcor