Caching records when using query to get from the store


#1

I’m using query to get items from my API, however when I come back to the route that loaded the data from the API I’m seeing a network call everytime. I want to prevent that. So I saw there is a shouldReloadAll and shouldBackgroundReloadAll that I could use to tell it to only background reload records if say it’s passed a certain time. However, those methods only appear to work for find and findAll.

My model hook looks like this

    var self = this;
    return this.store.query('item',{user_id: self.get('localUser.user.id'),status:1}).then(function(result){
      if(result){
        return result;
      } else {
        self.get('notification').notify({message: "An error occurred trying to get your watch list.",success:false});
        self.transitionTo('home');
      }
    });

Which gets turned into http://my.site/api/items/user/13193?status=1&key=XXXX with an adapter function

ajax: function(url, type, hash) {
    if (Ember.isEmpty(hash)) hash = {};
    if (Ember.isEmpty(hash.data)) hash.data = {};
    if (hash.data.auction_id) {
	    url = url + '/event/'+hash.data.auction_id;
	    delete hash.data.auction_id;
    }
    if (hash.data.user_id) {
	    url = url + '/user/'+hash.data.user_id;
	    delete hash.data.user_id;
    }
    return this._super(url, type, hash);
  }

(Yes the API I’m working with right now is really weird, I have plans to fix it later but don’t have green light to do so right now)

Most importantly right now I want to save the network call if I’ve already loaded items from the store.

Here’s the kicker, this call here is for watch-list items. There is another route items which loads items using the active_auction query param as seen in the ajax function in the adapter. So both of those are calling up items but they are different sets of items. So when items loads items it should cache those separately from the items that watch-list should cache. And when I enter either route it should check only for cached items in the store relevant to that particular URL.

So things here are a little confusing, can anyone help me?