diff --git a/lib/core/PackageRepository.js b/lib/core/PackageRepository.js index da3f0d77..5ee45f7d 100644 --- a/lib/core/PackageRepository.js +++ b/lib/core/PackageRepository.js @@ -134,6 +134,12 @@ PackageRepository.prototype.list = function () { return this._resolveCache.list(); }; +PackageRepository.clearRuntimeCache = function () { + ResolveCache.clearRuntimeCache(); + RegistryClient.clearRuntimeCache(); + resolverFactory.clearRuntimeCache(); +}; + // --------------------- PackageRepository.prototype._resolve = function (resolver, logger) { diff --git a/lib/core/resolverFactory.js b/lib/core/resolverFactory.js index 1bb875aa..337affb7 100644 --- a/lib/core/resolverFactory.js +++ b/lib/core/resolverFactory.js @@ -102,7 +102,7 @@ function getConstructor(source, config, registryClient) { }); } -function createResolver(decEndpoint, config, logger, registryClient) { +function createInstance(decEndpoint, config, logger, registryClient) { return getConstructor(decEndpoint.source, config, registryClient) .spread(function (ConcreteResolver, source, fromRegistry) { var resolverDecEndpoint = mout.object.pick(decEndpoint, ['name', 'target']); @@ -118,6 +118,12 @@ function createResolver(decEndpoint, config, logger, registryClient) { }); } -createResolver.getConstructor = getConstructor; +function clearRuntimeCache() { + mout.object.values(resolvers).forEach(function (ConcreteResolver) { + ConcreteResolver.clearRuntimeCache(); + }); +} -module.exports = createResolver; +module.exports = createInstance; +module.exports.getConstructor = getConstructor; +module.exports.clearRuntimeCache = clearRuntimeCache; diff --git a/lib/index.js b/lib/index.js index 6e024f85..0f888620 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,11 @@ var abbrev = require('abbrev'); var mout = require('mout'); var commands = require('./commands'); +var PackageRepository = require('./core/PackageRepository'); -var abbreviations; +var abbreviations = abbrev(names(commands)); +abbreviations.i = 'install'; +abbreviations.rm = 'uninstall'; function names(obj, prefix, stack) { prefix = prefix || ''; @@ -21,12 +24,16 @@ function names(obj, prefix, stack) { return stack; } -abbreviations = abbrev(names(commands)); -abbreviations.i = 'install'; -abbreviations.rm = 'uninstall'; +function clearRuntimeCache() { + // Note that the runtime cache is only cleared statically + // If you got an instance of an architecture component that holds cache, + // you should get rid of it and instantiate a new one after calling this + PackageRepository.clearRuntimeCache(); +} module.exports = { commands: commands, config: require('./config'), - abbreviations: abbreviations + abbreviations: abbreviations, + reset: clearRuntimeCache };