Is Ember Data desigend for single-user applications only?


#1

Since a few months we consider the use of Ember Data in one of our Ember projects. Each time we start looking at it or create a spike, we are faced with the problem of data caching in the store (load once and never load again; unless you invalidate the cache).

Data caching might be good for data that never (or almost never) changes or for cases whereby a user always works on his “own” set of data. In multi-user, enterprise applications this is barely the case. Users are looking at views in which data records are constantly added, removed, modified, etc. What is a recommended practice to handle such cases ? Always invalidate the cache so that everything is always reloaded ? Or subscribe to update/add/remove events via websockets or long pulling process ? Or a combination of the 2 ? Or always reload everything ?

An application like Discourse is never caching; it reloads for each route/view tons of data. Similar approach to other live Ember apps …

A simple example: we have a scheduling application. Two users are looking at the same schedule. User 1 adds an appointment. This appointment will never show up in the view of user 2 … In the view of user 2, it is not simply adding this appointment via socket.io or similar; we also need to remove the free time slots, increase an appointment counter, remove the same patient from the waiting list on which he was, etc.

Looking forward to your feedback !


#2

I have built a sports website using Ember data and faced similar issue of stale data since scores change every minute. This is how I solved it in my own simple way.

In the link-to, instead of passing model object, only pass the id of the object so that model function is always called in Route.

Example model function in a Route: (Forcing to reload the model everytime)

 model: (params, transition) ->
  scheduled_match_id = params.scheduled_match_id
  scheduledMatch = @store.getById('scheduled_match', scheduled_match_id)

  unless Ember.isEmpty(scheduledMatch)
    scheduledMatch.reload()
  else
    @store.find('scheduled_match', scheduled_match_id)

#3

The REST Adapter is mostly for single-user applications. However, they’ve done an amazing job at abstracting away the persistence layer. Using web sockets, you can create your own adapter that can accept push updates from the server and make your application more realtime. And if I’m not mistaken, I remember reading somewhere on here that they’re planning on adding some realtime features to Ember-Data. (Likely after 1.0 though.)