-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·53 lines (45 loc) · 1.08 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const Plugin = require('@midgar/midgar/plugin')
const redisStore = require('cache-manager-redis-store');
const utils = require('@midgar/utils')
/**
* MidgarRedisCache plugin
*
* Add redis cache storage
*/
class MidgarRedisCache extends Plugin {
/**
* Init plugin
*/
async init() {
this.pm.on('@midgar/cache:beforeInit', (...args) => {
return this._beforeCacheInit(...args)
})
}
/**
* Before cache init callback
*
* Add the redis cache store
*/
async _beforeCacheInit({ cacheService }) {
await cacheService.addStore('redis', (key) => {
return this._getStoreConfig(key)
})
}
/**
* Return the config to create store instance
*
* @param {*} key
*/
_getStoreConfig(key) {
const midgarConfig = this.midgar.config.cache && this.midgar.config.cache[key] ? this.midgar.config.cache[key] : {}
const config = utils.assignRecursive({
host: 'localhost',
port: 6379,
db: 0,
ttl: 600,
}, midgarConfig)
config.store = redisStore
return config
}
}
module.exports = MidgarRedisCache