ember.js - Ember-Data .find() vs .all() - how to control cache? -
i told in order not make request time, 1 can use .all() method load data kept in store. how ember deal cache? have couple of questions.
how control cache? when use .find() , when .all(). use .find() , .all()? how long?
does .all() have expiration date after time can make new request? or uses local storage have clear manually?
suppose have data i'd refresh once week? how should go this? every time enter or re-visit same route new request made. how can avoid this?
so start answering question comment:
i'd rather know how can load data when app starts (not via routes don't have update often). possible
so ok technically still via routes, best way load data when app "starts" via application route's model hook.
app.applicationroute = ember.route.extend({ model: function({ return app.post.find(); }) })
the router wait promise returned find() resolve, can sure response server has come before other routes entered.
how control cache?
mostly don't worry it. can refresh() individual record after timeout if needed.
when use .find() , when .all(). use .find() , .all()? how long?
depends want achieve. in our app use find() in application route, either all() or filter() in other routes.
does .all() have expiration date after time can make new request?
nope. never make new request
or uses local storage have clear manually?
it not use local storage, records in memory. sure f5 clear cache.
suppose have data i'd refresh once week? how should go this? every time enter or re-visit same route new request made. how can avoid this?
so ok let's assume use find() in application route, , user keeps browser open 1 week , records have expired. there many ways refresh, what's easy/best depends on if expire @ once or if time-out 1 @ time.
- have timer checks expired records , calls refresh() needed.
- have ping model update on schedule. when server responds update can sideload changed records.
- or can refresh browser once per week (via window.location...)
Comments
Post a Comment