How does ember without ember data deal with model caching?


I wonder how ember without ember data deals with model caching, as in how can I keep a cache around of the models I’ve created with fine grained control over invalidation from said cache?


Good question Yves. The most simple answer is use Ember data. Are there any particular reasons that you do not want/can use ED ?



My understanding is that Ember simply does not do this because that’s what ember data is supposed to do. As far as I know, Ember doesn’t actually care what type of object you give your controllers as a model.

Internally, ember data uses a Store, which is really just a hash of types that map to all known models. When you ask the store for a specific model, it looks to see if it already knows about it. If it does, it returns the known model instance. If it doesn’t, it sends a request to the persistence layer to go get it, after which it stashes the new record into the internal hash map (which ember-data calls a typeMap).

Ember-data gives you this out of the box, and it’s definitely the most stable part of Ember-data, in my opinion. I’d say give ember-data a try, but if that’s out of the question, then you’ll need to replicate that functionality of the Store to achieve what you want.

If you want an idea of how they do it, checkout and search for typeMaps and typeMapFor. That should lead you to the logic of the store that deals with the actual caching of records.