Does ember-data subsequent find generates XHR every time without caching?

74 Views Asked by At

I have an app built using ember-cli 0.2.5 (which is Ember 1.12.0 and Ember-Data 1.0.0-beta.17).

My models' store.find() always generate XHR request to my backend. I would expect subsequent route accesses to use the store's cache.

I have two routes, router.js is:

Router.map(function() { this.route('rules', {path: '/rules'}); this.route('users', {path: '/users'}); });

The routes models are:

Ember.Route.extend({ model: function (params) { return this.store.find('user'); } });

and

Ember.Route.extend({ model: function (params) { return this.store.find('rule'); } });

I am using the RESTAdapter and targeting an apache server which executes a perl cgi. The returned JSON (snippet) is:

{"rules":[{"canAutoUnblock":1,"creator":"spaling","status":null,"autoUnblockDate":"2015-05-30","createTime":"2015-01-19 19:59:56","privComment":"not private","pubComment":"Port scanning the Library","id":12,"ipaddr":"31.7.59.152"},{"canAutoUnblock":0,"creator":"spaling","status":"delete","autoUnblockDate":null,"createTime":"2015-01-19 19:59:56","privComment":"private","pubComment":"public","id":13,"ipaddr":"31.7.59.160"},

formatted ...

{ rules: [ { canAutoUnblock: 1, creator: "spaling", status: null, autoUnblockDate: "2015-05-30", createTime: "2015-01-19 19:59:56", privComment: "not private", pubComment: "Port scanning the Library", id: 12, ipaddr: "31.7.59.152" }, { canAutoUnblock: 0, creator: "spaling", status: "delete", autoUnblockDate: null, createTime: "2015-01-19 19:59:56", privComment: "private", pubComment: "public", id: 13, ipaddr: "31.7.59.160" },

Any advice greatly appreciated.

Barry

1

There are 1 best solutions below

4
On BEST ANSWER

This is expected behavior for find with no additional parameters.

store.find('modelName')

This will ask the adapter's findAll method to find the records for the given type, and return a promise that will be resolved once the server returns the values. The promise will resolve into all records of this type present in the store, even if the server only returns a subset of them.

See http://emberjs.com/api/data/classes/DS.Store.html#method_find

If you want cached records only use

store.all('modelName')

http://emberjs.com/api/data/classes/DS.Store.html#method_all