findRecord, findAll and peekRecord

Load One, Load Many, or Read From Cache

findRecord, findAll and peekRecord

findRecord fetches by id, findAll returns the full collection, and peekRecord pulls from the cache without making a request.

4 min read Level 2/5 #ember#ember-data#store
What you'll learn
  • Use the findRecord method with a type and id
  • Use findAll for full collections
  • Use peekRecord for cache-only sync reads

These three store methods cover most reads. Each has different semantics — pick based on whether you want fresh data, cached data, or one specific record.

findRecord

const post = await this.store.findRecord('post', 42);
  • First call: fetches GET /posts/42, caches the result, returns it.
  • Second call: returns the cached record immediately (still a Promise).
  • Force refresh:
await this.store.findRecord('post', 42, { reload: true });

findAll

const posts = await this.store.findAll('post');
  • First call: fetches GET /posts and caches all results.
  • Later calls: returns the cached collection.
  • Background refresh:
await this.store.findAll('post', { backgroundReload: true });

Returns the cache instantly, then quietly re-fetches and updates records as the response arrives.

peekRecord and peekAll

These never hit the network. They return whatever the store has cached, or null for a missing record.

const cached  = this.store.peekRecord('post', 42); // sync
const allInCache = this.store.peekAll('post');     // sync, live array

peekAll returns a live record array — it updates as records are added, removed, or unloaded.

When To Pick Which

  • Page load that needs fresh data: findRecord / findAll.
  • Side panel that just shows what’s already loaded: peekRecord / peekAll.
  • Snappy UX with eventual consistency: findAll(..., { backgroundReload: true }).
query and queryRecord →