'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); } } }); }