Find cached methods


I’m working on an application whose a bunch of records are only updated (backend side) once a day. It seems totally useless to request the server (via the store) every time the app need to get all these kind of records.

I’ve reopened the DS.Store and added two “find cached” methods with cache expiration options :

  • findAllCached to get all records
  • findQueryCached to query some records

Both methods have expiration options :

  • for, to define an expiration period
  • until, to define an expiration date

These methods request the server only if records are not yet cached.

findAllCached is based on findAll and all DS.Store methods.

findQueryCached is based on findQuery method plus a cache system linked to model metadata object.

Examples :"user", { for: moment.duration(1, "hours") });"user", { until: moment().add(1, "hours") });"post", { filter: "active" }, { for: moment.duration(1, "hours") });"post", { filter: "active" }, { until: moment().add(1, "hours") });

Here is a gist of this draft hack :

And a JsBin with a basic use case. Cars records are cached for one hour VS Trucks records are not cached.

What you guys are thinking about ? Useless ? Useful ?

Can’t wait to hear the Ember community about that.