diff --git a/lib/local-storage.js b/lib/local-storage.js index 1c4fc66a1..342404464 100644 --- a/lib/local-storage.js +++ b/lib/local-storage.js @@ -167,7 +167,7 @@ Storage.prototype.update_versions = function(name, newdata, callback) { } for (var up in newdata._uplinks) { var need_change = - !utils.is_object(data._uplinks[up]) || (newdata._uplinks[up].etag !== data._uplinks[up].etag) + !utils.is_object(data._uplinks[up]) || (newdata._uplinks[up].etag !== data._uplinks[up].etag || (newdata._uplinks[up].fetched !== data._uplinks[up].fetched)) if (need_change) { change = true diff --git a/lib/storage.js b/lib/storage.js index ffbbbe6a9..0deb33c6a 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -339,10 +339,19 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options, async.map(uplinks, function(up, cb) { var _options = Object.create(options) - if (utils.is_object(pkginfo._uplinks[up.upname])) + if (utils.is_object(pkginfo._uplinks[up.upname])) { + var fetched = pkginfo._uplinks[up.upname].fetched + if (fetched && fetched > (Date.now() - up.maxage)) { + return cb() + } + _options.etag = pkginfo._uplinks[up.upname].etag + } up.get_package(name, _options, function(err, up_res, etag) { + if (err && err.message === "bad status code: 304") + pkginfo._uplinks[up.upname].fetched = Date.now() + if (err || !up_res) return cb(null, [err || new Error('no data')]) try { @@ -356,7 +365,8 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options, } pkginfo._uplinks[up.upname] = { - etag: etag + etag: etag, + fetched: Date.now() } try { diff --git a/lib/up-storage.js b/lib/up-storage.js index b1dc088c0..5eb36cd2e 100644 --- a/lib/up-storage.js +++ b/lib/up-storage.js @@ -20,6 +20,7 @@ function Storage(config, mainconfig) { this.logger = Logger.logger.child({sub: 'out'}) this.server_id = mainconfig.server_id + this.maxage = (parseInt(this.config.maxage, 10) || 0) * 1000 this.url = URL.parse(this.config.url) if (this.url.hostname === 'registry.npmjs.org') { // npm registry is too slow working with ssl :(