-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.js
63 lines (55 loc) · 1.45 KB
/
Main.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
54
55
56
57
58
59
60
61
62
63
const { Operation } = require("./Operation/OperationClass");
const path = require("path");
const { GlobalData } = require("./DAO/GlobalData");
class Main {
static fileDefault = path.join(__dirname, "..", "data");
constructor(filepath) {
if (typeof filepath === "string" || typeof filepath === "undefined") {
let fileDefaultNew = path.join(__dirname, "..", "data");
if (!filepath) {
filepath = fileDefaultNew;
}
const dsFileName = GlobalData.dataStoreFileName;
if (!dsFileName) {
GlobalData.setDataStoreFileName(filepath);
}
}
}
/**
* To create user defined file path
* @param {*} filepath
*/
static setFileName(filepath) {
if (filepath === " ") {
filepath = this.fileDefault;
}
const dsFileName = GlobalData.dataStoreFileName;
if (!dsFileName) {
GlobalData.setDataStoreFileName(filepath);
}
}
/**
* Entry method to add the key-value pair
* @param {*} key
* @param {*} value
* @param {*} timeToLive
*/
async create(key, value, timeToLive) {
await Operation.createOperation(key, value, timeToLive);
}
/**
* Entry method to read the value based on the given key
* @param {*} key
*/
async read(key) {
return await Operation.readOperation(key);
}
/**
* Entry method to delete the given key
* @param {*} key
*/
async delete(key) {
return await Operation.deleteOperation(key);
}
}
exports.Locache = Main;