data icon indicating copy to clipboard operation
data copied to clipboard

Automatic unloading of models in long-lived apps

Open BryanCrotaz opened this issue 9 years ago • 4 comments

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?

BryanCrotaz avatar Jul 10 '15 00:07 BryanCrotaz

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.

stefanpenner avatar Jul 10 '15 00:07 stefanpenner

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 avatar Jan 06 '17 11:01 ReyAyanami

@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.

stefanpenner avatar Jan 06 '17 16:01 stefanpenner

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

runspired avatar Apr 21 '18 23:04 runspired

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.

runspired avatar Nov 17 '22 02:11 runspired