feat: #8824, cache refactor (#8851)

* feat: #8824, cache refactor

ability to disable caches
ability to download contents of cache
refactor cache modules to remove duplicated code

* fix: remove duplicate hit/miss tracking

check cacheEnabled in getUncachedKeys
This commit is contained in:
Barış Soner Uşaklı
2020-11-06 23:13:12 -05:00
committed by GitHub
parent bcbc085497
commit f1f9b225b0
23 changed files with 226 additions and 199 deletions

View File

@@ -29,7 +29,7 @@ module.exports = function (module) {
throw err;
}
cache.delObjectCache(key);
cache.del(key);
};
module.setObjectField = async function (key, field, value) {
@@ -164,7 +164,7 @@ module.exports = function (module) {
});
await module.client.collection('objects').updateOne({ _key: key }, { $unset: data });
cache.delObjectCache(key);
cache.del(key);
};
module.incrObjectField = async function (key, field) {
@@ -191,13 +191,13 @@ module.exports = function (module) {
bulk.find({ _key: key }).upsert().update({ $inc: increment });
});
await bulk.execute();
cache.delObjectCache(key);
cache.del(key);
const result = await module.getObjectsFields(key, [field]);
return result.map(data => data && data[field]);
}
const result = await module.client.collection('objects').findOneAndUpdate({ _key: key }, { $inc: increment }, { returnOriginal: false, upsert: true });
cache.delObjectCache(key);
cache.del(key);
return result && result.value ? result.value[field] : null;
};
};