Ember.js Data how to clear datastore
Solution 1
Clearing the data store is not yet supported in Ember-Data. There is an open issue concerning this on the Github tracker.
Solution 2
I know this question is from 2013. But since Ember Data 1.0.0-beta.17 (May 10, 2015) there's a straightforward way of clearing the datastore:
store.unloadAll()
(More here: http://emberigniter.com/clear-ember-data-store/)
Solution 3
It looks like, as of today, there is still no generic way of fully forcing a store cleanup. The simplest workaround seems to loop through all your types (person
, ...) and do:
store.unloadAll('person');
As seen here
Solution 4
A cleaner & generic approach. Just extend or reopen store & add a clear method like this.
DS.Store.extend({
clear: function() {
for(var key in this.typeMaps)
{
this.unloadAll(this.typeMaps[key].type);
}
}
});
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I am experiementing with Ember.js and have setup a small app where users can login and logout. When the user logs out I want to clear all of the currently cached records in the Data Store. Is there a way to do this or would I have to force the browser to reload the page?
-
blueFast almost 10 yearsThis is deleting the records, which is way more than removing them from the store. This is potentially dangerous, causing permanent data loss in the backend (Delete Records)
-
blueFast almost 10 yearsThat issue is closed, but I still see no method of clearing the store without resetting the application: I need to clear the store for debugging purposes, potentially re-requesting data from the backend, without otherwise affecting the state of my application (I want to stay in the same route, for example). Is this possible?
-
Daniel almost 9 yearsI don't know when it was introduced but the current documentation states that you can just do
store.unloadAll()
to unload all records.