0

Whenever I navigate from /users/1 to /users Ember-Data makes a new request. At this point it isn't a problem, but when I re-visit /comments route, the DOM elements are duplicated - it didn't happen on fixtures, but when we switched to JSON it appeared.

Shouldn't requests be cached? I think I read that they should and are.

Ember-Data Last commit: 6140f7d (2013-04-11 15:48:46 -0700)

in reply to the comment

my routes are set up as follows:

index route

App.IndexRoute = Ember.Route.extend
  redirect: ->
    this.transitionTo 'users'

users route

App.UsersRoute = Ember.Route.extend
  setupController: (controller, model) ->
    this.controllerFor('users').set 'content', App.User.find()
    this.controllerFor('currentUser').set 'content', App.CurrentUser.find 1

comments route

App.CommentsRoute = Ember.Route.extend
  model: ->
    App.Comment.find()

  setupController: (controller, model) ->
    @controllerFor('currentUser').set 'content', App.CurrentUser.find 1
wryrych
  • 1,765
  • 4
  • 20
  • 31

1 Answers1

4

I think what you are looking for is

App.Comment.all();

which will take all models that are currently cached inside the store as opposed to

App.Comment.find();

which will fetch all models from server and reloads current store cache.

Myslik
  • 1,178
  • 6
  • 14
  • So, how should I go about it? When an app starts should I call .find() and then only .all() if I know that the data won't be updated for some time? – wryrych May 13 '13 at 17:22
  • I suppose that is one way how to do it or you can lazily call `find()` on entering the route the first time. – Myslik May 13 '13 at 18:34
  • OK, thank you, but could you tell me when the cache is cleared? Suppose that I want some data to update only once a week but I don't mind using F5 button. Will cache be cleared after clicking on F5 or does Ember use LocalStorage so that I have to clear it manually? Or maybe .all() has some expiration date? Hm, I think that I should ask in another thread. – wryrych May 14 '13 at 06:40
  • Unless you rewrite it yourself, cache is held only till you reload the page. – Myslik May 14 '13 at 10:06