[英]Cache a record when using Query Params in the call? Ember-data
我有这条路线检索2个模型:
App.PanelRoute = Ember.Route.extend({
model: function(){
var topologymin = this.store.find('topologymin');
var metricmap = this.store.find('metricmap', { param1: 'something'})
return Ember.RSVP.hash({
topologymin: topologymin,
metricmap: metricmap
});
});
这会打2个电话:
http://localhost/topologymins
http://localhost/metricmaps?param1=something
如果我再次前往另一条路线,它会再次使用参数调用,而不是另一条:
http://localhost/metricmaps?param1=something
但是,由于它是同一个检索相同记录的调用,我希望它们像在另一个调用中一样被缓存。
它如何知道何时调用服务器以及何时不需要? 有可能吗?
我的模特:
App.Topologymin = DS.Model.extend({
siteGroup: DS.attr('string'),
sites: DS.hasMany('site')
});
App.Metricmap = DS.Model.extend({
profile: DS.attr('string'),
link: DS.attr('string'),
services: DS.attr()
});
当您根据参数触发请求时,Ember Data不知道这些参数是如何必然转化为模型的(也就是说它不知道您拥有所有具有某种关系的记录param1)。 您可以自己缓存它,但是您仍然需要某种方式来知道商店中其他记录的那些记录。
App.PanelRoute = Ember.Route.extend({
model: function(){
var met = this.get('fetchedBeforePromise'),
topologymin = this.store.find('topologymin'),
metricmap = met || this.store.find('metricmap', { param1: 'something'});
this.set('fetchedBeforePromise', metricmap);
return Ember.RSVP.hash({
topologymin: topologymin,
metricmap: metricmap
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.