-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (23 loc) · 818 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const Cacheman = require('recacheman-redis');
const { Query } = require('mongoose');
const RedisManager = require('./src/RedisManager');
const extendQuery = require('./src/extendQuery');
const extendModel = require('./src/extendModel');
const warnNoInit = require('./src/warnNoInit');
extendModel();
extendQuery();
module.exports = function (options) {
const cacheman = new Cacheman(options);
const redisManager = new RedisManager(cacheman);
Query.redisManager = redisManager;
};
module.exports.clearCache = async function (key) {
if (!Query.redisManager) return warnNoInit();
if (!key) return Query.redisManager.clear();
else return Query.redisManager.del(key);
};
Object.defineProperty(module.exports, 'redisManager', {
get: function () {
return Query.redisManager;
}
});