if (typeof cb !== "function") cb = staleOk, staleOk = false
if (typeof cb !== "function") cb = nofollow, nofollow = false
if (typeof cb !== "function") cb = timeout, timeout = -1
- if (typeof cb !== "function") cb = version, version = null
timeout = Math.min(timeout, this.conf.get('cache-max') || 0)
timeout = Math.max(timeout, this.conf.get('cache-min') || -Infinity)
&& process.env.COMP_POINT !== undefined
) timeout = Math.max(timeout, 60000)
+ var cache = this.cacheFile(this.registry + uri) + "/.cache.json"
+
// /-/all is special.
// It uses timestamp-based caching and partial updates,
// because it is a monster.
if (uri === "/-/all") {
- return requestAll.call(this, cb)
+ return requestAll.call(this, cache, cb)
}
- var cacheUri = uri
- // on windows ":" is not an allowed character in a foldername
- cacheUri = cacheUri.replace(/:/g, '_').replace(/\?write=true$/, '')
- var cache = path.join(this.conf.get('cache'), cacheUri, ".cache.json")
-
// If the GET is part of a write operation (PUT or DELETE), then
// skip past the cache entirely, but still save the results.
if (uri.match(/\?write=true$/))
}.bind(this))
}
-function requestAll (cb) {
- var cache = path.join(this.conf.get('cache'), "/-/all", ".cache.json")
-
- mkdir(path.join(this.conf.get('cache'), "-", "all"), function (er) {
+function requestAll (cache, cb) {
+ mkdir(path.dirname(cache), function (er) {
fs.readFile(cache, function (er, data) {
- if (er) return requestAll_.call(this, 0, {}, cb)
+ if (er) return requestAll_.call(this, 0, {}, cache, cb)
try {
data = JSON.parse(data)
} catch (ex) {
fs.writeFile(cache, "{}", function (er) {
if (er) return cb(new Error("Broken cache."))
- return requestAll_.call(this, 0, {}, cb)
+ return requestAll_.call(this, 0, {}, cache, cb)
}.bind(this))
}
var t = +data._updated || 0
- requestAll_.call(this, t, data, cb)
+ requestAll_.call(this, t, data, cache, cb)
}.bind(this))
}.bind(this))
}
-function requestAll_ (c, data, cb) {
+function requestAll_ (c, data, cache, cb) {
// use the cache and update in the background if it's not too old
if (Date.now() - c < 60000) {
cb(null, data)
uri = "/-/all"
}
- var cache = path.join(this.conf.get('cache'), "-/all", ".cache.json")
this.request('GET', uri, function (er, updates, _, res) {
if (er) return cb(er, data)
var headers = res.headers