joyent/node-triton#158 tritonapi image cache never expires
Reviewed by: Chris Burroughs <chris.burroughs@joyet.com> Approved by: Chris Burroughs <chris.burroughs@joyet.com>
This commit is contained in:
parent
c7140609f0
commit
2453bc12e8
@ -7,6 +7,8 @@ Known issues:
|
|||||||
|
|
||||||
## not yet released
|
## not yet released
|
||||||
|
|
||||||
|
- [joyent/node-triton#158] tritonapi image cache never expires
|
||||||
|
|
||||||
- [joyent/node-triton#153] Bump restify-clients dep. Thanks, github.com/tomgco.
|
- [joyent/node-triton#153] Bump restify-clients dep. Thanks, github.com/tomgco.
|
||||||
|
|
||||||
- [joyent/node-triton#154] Fix `triton cloudapi ...` after #108 changes.
|
- [joyent/node-triton#154] Fix `triton cloudapi ...` after #108 changes.
|
||||||
|
@ -375,16 +375,21 @@ TritonApi.prototype._cacheGetJson = function _cacheGetJson(key, cb) {
|
|||||||
assert.string(key, 'key');
|
assert.string(key, 'key');
|
||||||
assert.func(cb, 'cb');
|
assert.func(cb, 'cb');
|
||||||
|
|
||||||
|
var ttl = 5 * 60 * 1000; // timeout of cache file info (ms)
|
||||||
|
|
||||||
var keyPath = path.resolve(this.cacheDir, key);
|
var keyPath = path.resolve(this.cacheDir, key);
|
||||||
|
fs.stat(keyPath, function (statErr, stats) {
|
||||||
|
if (!statErr &&
|
||||||
|
stats.mtime.getTime() + ttl >= (new Date()).getTime()) {
|
||||||
fs.readFile(keyPath, 'utf8', function (err, data) {
|
fs.readFile(keyPath, 'utf8', function (err, data) {
|
||||||
if (err && err.code === 'ENOENT') {
|
if (err && err.code === 'ENOENT') {
|
||||||
self.log.trace({keyPath: keyPath},
|
self.log.trace({keyPath: keyPath},
|
||||||
'cache file does not exist');
|
'cache file does not exist');
|
||||||
return cb();
|
cb();
|
||||||
} else if (err) {
|
} else if (err) {
|
||||||
self.log.warn({err: err, keyPath: keyPath},
|
self.log.warn({err: err, keyPath: keyPath},
|
||||||
'error reading cache file');
|
'error reading cache file');
|
||||||
return cb();
|
cb();
|
||||||
}
|
}
|
||||||
var obj;
|
var obj;
|
||||||
try {
|
try {
|
||||||
@ -397,12 +402,18 @@ TritonApi.prototype._cacheGetJson = function _cacheGetJson(key, cb) {
|
|||||||
self.log.warn({err: err2},
|
self.log.warn({err: err2},
|
||||||
'failed to remove JSON cache file');
|
'failed to remove JSON cache file');
|
||||||
}
|
}
|
||||||
cb(err2);
|
cb();
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cb(null, obj);
|
cb(null, obj);
|
||||||
});
|
});
|
||||||
|
} else if (statErr && statErr.code !== 'ENOENT') {
|
||||||
|
cb(statErr);
|
||||||
|
} else {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user