You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
589 B
JavaScript
24 lines
589 B
JavaScript
'use strict';
|
|
|
|
const rfr = require("rfr");
|
|
const errors = rfr("lib/util/errors");
|
|
|
|
module.exports = function(db, collectionName) {
|
|
return Promise.try(() => {
|
|
return db.collection(collectionName);
|
|
}).then((cacheCollection) => {
|
|
return {
|
|
CacheError: errors.CacheError,
|
|
get: function(packageName) {
|
|
try {
|
|
return cacheCollection.findOne({$cacheKey: packageName});
|
|
} catch (err) { // FIXME
|
|
throw new errors.CacheError("Not in cache");
|
|
}
|
|
},
|
|
set: function(packageName, metadata) {
|
|
return cacheCollection.upsertBy("$cacheKey", metadata);
|
|
}
|
|
}
|
|
});
|
|
} |