Skip to content

Commit

Permalink
Remove unnecessary resolverCacheKey
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Mar 4, 2018
1 parent d64b165 commit 3065c44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
22 changes: 7 additions & 15 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ export default class Container {
return { [OWNER]: this.owner };
}

_resolverCacheKey(name) {
return this.registry.resolverCacheKey(name);
}

/**
Given a fullName, return the corresponding factory. The consumer of the factory
is responsible for the destruction of any factory instances, as there is no
Expand Down Expand Up @@ -230,8 +226,7 @@ function lookup(container, fullName, options = {}) {
}

if (options.singleton !== false) {
let cacheKey = container._resolverCacheKey(normalizedName);
let cached = container.cache[cacheKey];
let cached = container.cache[normalizedName];
if (cached !== undefined) {
return cached;
}
Expand All @@ -242,8 +237,7 @@ function lookup(container, fullName, options = {}) {


function factoryFor(container, normalizedName, fullName) {
let cacheKey = container._resolverCacheKey(normalizedName);
let cached = container.factoryManagerCache[cacheKey];
let cached = container.factoryManagerCache[normalizedName];

if (cached !== undefined) { return cached; }

Expand All @@ -263,7 +257,7 @@ function factoryFor(container, normalizedName, fullName) {
manager = wrapManagerInDeprecationProxy(manager);
}

container.factoryManagerCache[cacheKey] = manager;
container.factoryManagerCache[normalizedName] = manager;
return manager;
}

Expand Down Expand Up @@ -293,8 +287,7 @@ function instantiateFactory(container, normalizedName, fullName, options) {
// SomeClass { singleton: true, instantiate: true } | { singleton: true } | { instantiate: true } | {}
// By default majority of objects fall into this case
if (isSingletonInstance(container, fullName, options)) {
let cacheKey = container._resolverCacheKey(normalizedName);
return container.cache[cacheKey] = factoryManager.create();
return container.cache[normalizedName] = factoryManager.create();
}

// SomeClass { singleton: false, instantiate: true }
Expand Down Expand Up @@ -364,13 +357,12 @@ function resetCache(container) {
}

function resetMember(container, fullName) {
let cacheKey = container._resolverCacheKey(fullName);
let member = container.cache[cacheKey];
let member = container.cache[fullName];

delete container.factoryManagerCache[cacheKey];
delete container.factoryManagerCache[fullName];

if (member) {
delete container.cache[cacheKey];
delete container.cache[fullName];

if (member.destroy) {
member.destroy();
Expand Down
23 changes: 8 additions & 15 deletions packages/container/lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ export default class Registry {
assert(`Attempting to register an unknown factory: '${fullName}'`, factory !== undefined);

let normalizedName = this.normalize(fullName);
let cacheKey = this.resolverCacheKey(normalizedName);
assert(`Cannot re-register: '${fullName}', as it has already been resolved.`, !this._resolveCache[cacheKey]);
assert(`Cannot re-register: '${fullName}', as it has already been resolved.`, !this._resolveCache[normalizedName]);

this._failSet.delete(cacheKey);
this._failSet.delete(normalizedName);
this.registrations[normalizedName] = factory;
this._options[normalizedName] = options;
}
Expand All @@ -180,14 +179,13 @@ export default class Registry {
assert('fullName must be a proper full name', this.isValidFullName(fullName));

let normalizedName = this.normalize(fullName);
let cacheKey = this.resolverCacheKey(normalizedName);

this._localLookupCache = Object.create(null);

delete this.registrations[normalizedName];
delete this._resolveCache[cacheKey];
delete this._resolveCache[normalizedName];
delete this._options[normalizedName];
this._failSet.delete(cacheKey);
this._failSet.delete(normalizedName);
}

/**
Expand Down Expand Up @@ -567,10 +565,6 @@ export default class Registry {
return injections;
}

resolverCacheKey(name) {
return name;
}

/**
Given a fullName and a source fullName returns the fully resolved
fullName. Used to allow for local lookup.
Expand Down Expand Up @@ -685,10 +679,9 @@ function resolve(registry, normalizedName, options) {
}
}

let cacheKey = registry.resolverCacheKey(normalizedName);
let cached = registry._resolveCache[cacheKey];
let cached = registry._resolveCache[normalizedName];
if (cached !== undefined) { return cached; }
if (registry._failSet.has(cacheKey)) { return; }
if (registry._failSet.has(normalizedName)) { return; }

let resolved;

Expand All @@ -701,9 +694,9 @@ function resolve(registry, normalizedName, options) {
}

if (resolved === undefined) {
registry._failSet.add(cacheKey);
registry._failSet.add(normalizedName);
} else {
registry._resolveCache[cacheKey] = resolved;
registry._resolveCache[normalizedName] = resolved;
}

return resolved;
Expand Down

0 comments on commit 3065c44

Please sign in to comment.