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.

22 lines
526 B
JavaScript

'use strict';
const rfr = require("rfr");
const errors = rfr("lib/util/errors");
module.exports = function(db, collectionName) {
let cacheCollection = db.collection(collectionName);
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);
}
}
}