Skip to content


Subversion checkout URL

You can clone with
Download ZIP


clearing datastore / session #13

heartsentwined opened this Issue · 8 comments

4 participants


Basically a duplicate issue / feature request of emberjs/data#235 - is there a way to clear the loaded models of epf? Or of a session?

The closest I can find about this functionality in epf: (as far as I can understand the code,) creating a child session and loading all models into it, then discarding the session, won't "discard" the models themselves. Subsequent calls to load(Model, id) will still return the previously loaded model from client side.

Use case: authenticated app. On sign out, one expects the models loaded into the previous signed in session to be inaccessible in any way. An even better approach would be to allow devs to specify which models are cleared, and which are not, somewhere in model declarations. That way, "public" / "common" models like product can be preserved and cached; while "private" models like cart can be destroyed.

Current workaround is to force a browser reload on sign out, hence destroying the ember app altogether, and restarting it.


@heartsentwined How about using session.destroy() then recreating it on the container.

container.register('session:main', App.DefaultSession || Ep.Session);

I'm still figuring out Epf, not sure this is the right way.


Folks over at ember-data recommended a similar solution too, but got rejected by the devs on grounds that

we actually pass the store reference around and those references would not be updated. We probably should have a method to do this.

Would love to hear from @ghempton on this suggestion.


This is a good question. Creating a new top-level session (e.g. adapter.newSession()) is the answer I want to give, but alas the ember-data folks are correct that the injected references will not be updated.

If we want the references to be updated, a higher level approach needs to be taken and all the controllers and routes need to be re-created. Perhaps the entire application could be reset using Application.reset()?

Alternatively, it would be fairly straightforward to create an api such as session.unload(), but that seems kind of fragile for this use case. Thoughts?


I haven't dug deep yet, but from the observed behavior it seems that load(), find(), and friends (if any) does this:

  1. if the passed tuple of ModelClass + id is present in cache, return it immediately
  2. otherwise query the server for it

So I think that the unload() api can simply clear the cache, and mark all tuples as unseen. This will allow you to maintain the same reference to the session. However, I am not sure if there are other traces unique to the current session that ought to be cleared.

An Application.reset() is as unattractive as the forced-refresh workaround. Say Alice is looking at a dress, and urges her friend Cindy to buy it. Alas, Alice needs to log out so that Cindy can log into her account. The refresh / app-reset approach will clear everything, then try to reload it from the URL (and maybe cookies) alone. Granted, a well-designed app should be able to do that, although it will quickly get tedious to keep track of, say, the "yellow" color checkbox right next to the dress. Not to mention that the page goes "unresponsive" for a while (waiting for server to confirm log out success), then goes "blank" (refresh), and yet more wait time for the app-reload. If possible I would prefer to keep the ember app in place, and just let the little sign in/out box at the corner does its magic without interrupting Cindy's gaze at the beautiful dress. A customer!


As discyssion over at the ember-data thread has mentioned, Application.reset() is good for unit-testing though. However, it's even better to destroy() everything - so that already takes care of this use case IMO.


I'm for adding an unload method. It shouldn't be too hard, short of a few edge cases. Will mark this issue as a feature request for it. This will also suffer from dangling references to unloaded models, however.

I can't help but wish it were easier to swap out session instances as this use case seems perfect for it. I wonder if there are some optimizations that can be done around App.reset (e.g. keeping the models around and manually adding to the session).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.