data
data copied to clipboard
Automatic unloading of models in long-lived apps
I'm building an app that will run for years at a time, so has to be ultra robust.
I'm looking at writing an extension for ember-data that will declaratively unload models when they're not needed any more (no routes or components need them). For example you could mark a model as being unloadable 10 minutes after its last use.
So the big question is how to detect that a model is no longer needed (let's assume that it's ok to reload it from the server if we need it in future). Would it be safe to say that a model can be unloaded if it has no observers actively watching it? Or is there a way of using a model that wouldn't involve an observer?
I don't believe this is possible without explicit ref counting done in user land, that is unless you are running on a platform that supports native WeakMaps.
Sorry, but is this function request still actual? Since major number of current browsers support WeakMap's maybe now it is possible to implement auto-unload
@ReyAyanami well, sorta. We are still missing some features, e.g. WeakMap make some of it possible but not all. Def an area that requires more exploration though.
We've implemented internal ref counting, we'er still missing some features but even in terms of giving app-devs high level tools for doing this on their own we don't have a great story yet. I've left some thoughts here: https://github.com/emberjs/data/issues/4938#issuecomment-383340318
Going to close this in favor of #8162 which will require either an RFC or some other library to explore via EmberData's public APIs. This is definitely achievable and if someone comes up with a good pattern we'd consider it for core.