joyent/node-triton#63 "triton images" with a filter should not be cached
This commit is contained in:
parent
f66e50c770
commit
b50f0c8aa1
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## 3.4.2 (not yet released)
|
## 3.4.2 (not yet released)
|
||||||
|
|
||||||
|
- #63 "triton images" with a filter should not be cached.
|
||||||
- #65 Fix `triton profile(s)` handling when the user has no profiles yet.
|
- #65 Fix `triton profile(s)` handling when the user has no profiles yet.
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,8 +220,11 @@ TritonApi.prototype._cacheGetJson = function _cacheGetJson(key, cb) {
|
|||||||
* CloudAPI listImages wrapper with optional caching.
|
* CloudAPI listImages wrapper with optional caching.
|
||||||
*
|
*
|
||||||
* @param opts {Object} Optional.
|
* @param opts {Object} Optional.
|
||||||
* - useCase {Boolean} Whether to use Triton's local cache.
|
* - useCache {Boolean} Default false. Whether to use Triton's local cache.
|
||||||
* - ... all other cloudapi ListImages options
|
* Note that the *currently* implementation will only use the cache
|
||||||
|
* when there are no filter options.
|
||||||
|
* - ... all other cloudapi ListImages options per
|
||||||
|
* <https://apidocs.joyent.com/cloudapi/#ListImages>
|
||||||
* @param {Function} callback `function (err, imgs)`
|
* @param {Function} callback `function (err, imgs)`
|
||||||
*/
|
*/
|
||||||
TritonApi.prototype.listImages = function listImages(opts, cb) {
|
TritonApi.prototype.listImages = function listImages(opts, cb) {
|
||||||
@ -237,14 +240,21 @@ TritonApi.prototype.listImages = function listImages(opts, cb) {
|
|||||||
var listOpts = common.objCopy(opts);
|
var listOpts = common.objCopy(opts);
|
||||||
delete listOpts.useCache;
|
delete listOpts.useCache;
|
||||||
|
|
||||||
var cacheKey = 'images.json';
|
// For now at least, we only cache full results (no filtering).
|
||||||
|
var useCache = Boolean(opts.useCache);
|
||||||
|
var cacheKey;
|
||||||
|
if (Object.keys(listOpts).length > 0) {
|
||||||
|
useCache = false;
|
||||||
|
} else {
|
||||||
|
cacheKey = 'images.json';
|
||||||
|
}
|
||||||
var cached;
|
var cached;
|
||||||
var fetched;
|
var fetched;
|
||||||
var res;
|
var res;
|
||||||
|
|
||||||
vasync.pipeline({funcs: [
|
vasync.pipeline({funcs: [
|
||||||
function tryCache(_, next) {
|
function tryCache(_, next) {
|
||||||
if (!opts.useCache) {
|
if (!useCache) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
self._cacheGetJson(cacheKey, function (err, cached_) {
|
self._cacheGetJson(cacheKey, function (err, cached_) {
|
||||||
@ -272,10 +282,11 @@ TritonApi.prototype.listImages = function listImages(opts, cb) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
function cacheFetched(_, next) {
|
function cacheFetched(_, next) {
|
||||||
if (!fetched) {
|
if (cacheKey && fetched) {
|
||||||
return next();
|
|
||||||
}
|
|
||||||
self._cachePutJson(cacheKey, fetched, next);
|
self._cachePutJson(cacheKey, fetched, next);
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
]}, function (err) {
|
]}, function (err) {
|
||||||
@ -311,7 +322,8 @@ TritonApi.prototype.getImage = function getImage(opts, cb) {
|
|||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self._cacheGetJson('images.json', function (err, images) {
|
var cacheKey = 'images.json';
|
||||||
|
self._cacheGetJson(cacheKey, function (err, images) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user