-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.js
More file actions
40 lines (34 loc) · 883 Bytes
/
cache.js
File metadata and controls
40 lines (34 loc) · 883 Bytes
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
'use strict';
const Redis = require('./redis');
const Config = require('./config');
const classesMapping = {
'redis': Redis
};
module.exports = class Cache {
constructor() {
this.status = Config.core.cache;
if( this.status ) {
this.engine = new classesMapping[Config.core.cacheEngine];
}
}
status() {
return this.status;
}
get(key, callback) {
if (this.status && key) {
this.engine.get(key)
.then((result) => {
callback(result);
}).catch((err) => {
callback(undefined);
});
} else {
callback(undefined);
}
}
set(key, value, expiration = undefined) {
if( this.status && key && value ) {
this.engine.set(key, value, expiration);
}
}
};