This commit is contained in:
Andris Reinman 2018-08-25 08:43:06 +03:00
parent ac205c2622
commit 2c92b98c8b
2 changed files with 122 additions and 122 deletions

View file

@ -1,54 +1,54 @@
'use strict';
class UserCache {
constructor(options) {
this.users = options.users;
this.redis = options.redis;
}
constructor(options) {
this.users = options.users;
this.redis = options.redis;
}
flush(user, callback) {
this.redis.del('cached:' + user, () => callback());
}
flush(user, callback) {
this.redis.del('cached:' + user, () => callback());
}
get(user, key, defaultValue, callback) {
this.redis.hget('cached:' + user, key, (err, value) => {
get(user, key, defaultValue, callback) {
this.redis.hget('cached:' + user, key, (err, value) => {
if (err) {
return callback(err);
}
if (value) {
return callback(null, Number(value));
}
this.users.collection('users').findOne(
{
_id: user
},
{
projection: {
[key]: true
}
},
(err, userData) => {
if (err) {
return callback(err);
}
if (!userData) {
return callback(null, defaultValue);
}
value = userData[key] || defaultValue;
this.redis.hset('cached:' + user, key, value, err => {
if (err) {
return callback(err);
return callback(err);
}
if (value) {
return callback(null, Number(value));
}
this.users.collection('users').findOne(
{
user
},
{
projection: {
[key]: true
}
},
(err, userData) => {
if (err) {
return callback(err);
}
if (!userData) {
return callback(null, defaultValue);
}
value = userData[key] || defaultValue;
this.redis.hset('cached:' + user, key, value, err => {
if (err) {
return callback(err);
}
return callback(null, value);
});
}
);
});
}
return callback(null, value);
});
}
);
});
}
}
module.exports = UserCache;

View file

@ -1,80 +1,80 @@
{
"name": "wildduck",
"version": "1.4.2",
"description": "IMAP/POP3 server built with Node.js and MongoDB",
"main": "server.js",
"scripts": {
"toc": "markdown-toc -i docs/api.md",
"test": "mongo --eval 'db.dropDatabase()' wildduck-test && redis-cli -n 13 flushdb && NODE_ENV=test grunt",
"apidoc": "apidoc -i lib/api/ -o docs/",
"show": "NODE_CONFIG_ONLY=true node server.js"
},
"keywords": [
"imap",
"mail server"
],
"author": "Andris Reinman",
"license": "EUPL-1.1+",
"devDependencies": {
"apidoc": "0.17.6",
"browserbox": "0.9.1",
"chai": "4.1.2",
"eslint-config-nodemailer": "1.2.0",
"grunt": "1.0.3",
"grunt-cli": "1.3.1",
"grunt-eslint": "21.0.0",
"grunt-mocha-test": "0.13.3",
"grunt-shell-spawn": "0.3.10",
"grunt-wait": "0.1.0",
"icedfrisby": "1.5.0",
"mailparser": "2.3.3",
"markdown-toc": "1.2.0",
"mocha": "5.2.0",
"request": "2.88.0"
},
"dependencies": {
"base32.js": "^0.1.0",
"bcryptjs": "2.4.3",
"bugsnag": "2.4.3",
"generate-password": "1.4.0",
"he": "1.1.1",
"html-to-text": "4.0.0",
"humanname": "0.2.2",
"iconv-lite": "0.4.24",
"ioredfour": "1.0.2-ioredis-02",
"ioredis": "4.0.0",
"isemail": "3.1.3",
"joi": "13.6.0",
"js-yaml": "3.12.0",
"key-fingerprint": "1.1.0",
"libbase64": "1.0.3",
"libmime": "4.0.1",
"libqp": "1.1.0",
"linkify-it": "2.0.3",
"mailsplit": "4.2.3",
"mobileconfig": "2.1.0",
"mongo-cursor-pagination": "^7.1.0",
"mongodb": "3.1.3",
"mongodb-extended-json": "1.10.0",
"node-forge": "0.7.6",
"nodemailer": "4.6.8",
"npmlog": "4.1.2",
"openpgp": "4.0.0",
"pem": "1.12.5",
"qrcode": "1.2.2",
"restify": "7.2.1",
"restify-logger": "2.0.1",
"seq-index": "1.1.0",
"smtp-server": "3.4.6",
"speakeasy": "2.0.0",
"tlds": "1.203.1",
"u2f": "0.1.3",
"utf7": "1.0.2",
"uuid": "3.3.2",
"wild-config": "1.3.6"
},
"repository": {
"type": "git",
"url": "git://github.com/wildduck-email/wildduck.git"
}
"name": "wildduck",
"version": "1.4.3",
"description": "IMAP/POP3 server built with Node.js and MongoDB",
"main": "server.js",
"scripts": {
"toc": "markdown-toc -i docs/api.md",
"test": "mongo --eval 'db.dropDatabase()' wildduck-test && redis-cli -n 13 flushdb && NODE_ENV=test grunt",
"apidoc": "apidoc -i lib/api/ -o docs/",
"show": "NODE_CONFIG_ONLY=true node server.js"
},
"keywords": [
"imap",
"mail server"
],
"author": "Andris Reinman",
"license": "EUPL-1.1+",
"devDependencies": {
"apidoc": "0.17.6",
"browserbox": "0.9.1",
"chai": "4.1.2",
"eslint-config-nodemailer": "1.2.0",
"grunt": "1.0.3",
"grunt-cli": "1.3.1",
"grunt-eslint": "21.0.0",
"grunt-mocha-test": "0.13.3",
"grunt-shell-spawn": "0.3.10",
"grunt-wait": "0.1.0",
"icedfrisby": "1.5.0",
"mailparser": "2.3.3",
"markdown-toc": "1.2.0",
"mocha": "5.2.0",
"request": "2.88.0"
},
"dependencies": {
"base32.js": "^0.1.0",
"bcryptjs": "2.4.3",
"bugsnag": "2.4.3",
"generate-password": "1.4.0",
"he": "1.1.1",
"html-to-text": "4.0.0",
"humanname": "0.2.2",
"iconv-lite": "0.4.24",
"ioredfour": "1.0.2-ioredis-02",
"ioredis": "4.0.0",
"isemail": "3.1.3",
"joi": "13.6.0",
"js-yaml": "3.12.0",
"key-fingerprint": "1.1.0",
"libbase64": "1.0.3",
"libmime": "4.0.1",
"libqp": "1.1.0",
"linkify-it": "2.0.3",
"mailsplit": "4.2.3",
"mobileconfig": "2.1.0",
"mongo-cursor-pagination": "^7.1.0",
"mongodb": "3.1.3",
"mongodb-extended-json": "1.10.0",
"node-forge": "0.7.6",
"nodemailer": "4.6.8",
"npmlog": "4.1.2",
"openpgp": "4.0.0",
"pem": "1.12.5",
"qrcode": "1.2.2",
"restify": "7.2.1",
"restify-logger": "2.0.1",
"seq-index": "1.1.0",
"smtp-server": "3.4.6",
"speakeasy": "2.0.0",
"tlds": "1.203.1",
"u2f": "0.1.3",
"utf7": "1.0.2",
"uuid": "3.3.2",
"wild-config": "1.3.6"
},
"repository": {
"type": "git",
"url": "git://github.com/wildduck-email/wildduck.git"
}
}