Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly reset container cache #15710

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ Container.prototype = {
@param {String} fullName optional key to reset; if missing, resets everything
*/
reset(fullName) {
if (fullName !== undefined) {
resetMember(this, this.registry.normalize(fullName));
} else {
if (fullName === undefined) {
resetCache(this);
} else {
resetMember(this, this.registry.normalize(fullName));
}
},

Expand Down Expand Up @@ -366,7 +366,8 @@ function destroyDestroyables(container) {

function resetCache(container) {
destroyDestroyables(container);
container.cache.dict = dictionary(null);
container.cache = dictionary(null);
container.factoryManagerCache = dictionary(null);
}

function resetMember(container, fullName) {
Expand Down
25 changes: 25 additions & 0 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,31 @@ QUnit.test('#factoryFor instance have a common parent', (assert) => {
assert.deepEqual(instance1.constructor, instance2.constructor);
});

QUnit.test('can properly reset cache', (assert) => {
let registry = new Registry();
let container = registry.container();

let Component = factory();
registry.register('component:foo-bar', Component);

let factory1 = container.factoryFor('component:foo-bar');
let factory2 = container.factoryFor('component:foo-bar');

let instance1 = container.lookup('component:foo-bar');
let instance2 = container.lookup('component:foo-bar');

assert.equal(instance1, instance2);
assert.equal(factory1, factory2);

container.reset();

let factory3 = container.factoryFor('component:foo-bar');
let instance3 = container.lookup('component:foo-bar');

assert.notEqual(instance1, instance3);
assert.notEqual(factory1, factory3);
});

QUnit.test('#factoryFor created instances come with instance injections', (assert) => {
let registry = new Registry();
let container = registry.container();
Expand Down