Is there a way to limit the amount of models that exist in the Ember Data store? The use case for this is a chat app. It cannot be slowly eating away at the browser's memory as more and more Message
models fill up. Preferably the oldest model would delete itself if there are more than 100 in store.
You can watch all the records of a type in the store, and delete them whenever there are more than you want. This could really live on any controller/route...
App.MessagesRoute = Em.Route.extend({
allMessages: function(){
return this.store.all('message');
}.property(),
messageCount: Em.computed.alias('allMessages.length'),
watchSize: function(){
var cnt = this.get('messageCount'),
messages;
if(cnt>100){
messages = this.get('allMessages').sortBy('messageDate').toArray().slice(100);
messages.forEach(function(message){
message.deleteRecord();
});
}
}.observes('messageCount')
});