UNPKG

887 BJavaScriptView Raw
1var { readFileSync, writeFileSync, existsSync, writeFile } = require("fs");
2var { tmpdir } = require("os");
3var path = require("path");
4var pkg = require("./package");
5
6var cachePath = path.join(tmpdir(), `ui5_cache_${pkg.version}`);
7
8class UI5Cache extends Map {
9
10 Persist() {
11 writeFileSync(cachePath, JSON.stringify([...this]), { encoding: "UTF-8" });
12 }
13
14 PersistAsync(){
15 writeFile(cachePath, JSON.stringify([...this]), { encoding: "UTF-8" }, ()=>{});
16 }
17
18}
19
20/**
21 * load cache
22 */
23UI5Cache.load = () => {
24 try {
25 if (existsSync(cachePath)) {
26 var binCache = readFileSync(cachePath, { encoding: "UTF-8" });
27 var binCacheObject = JSON.parse(binCache);
28 return new UI5Cache(binCacheObject);
29 } else {
30 return new UI5Cache();
31 }
32 } catch (error) {
33 // if some error happened
34 return new UI5Cache();
35 }
36};
37
38module.exports = {
39 UI5Cache
40};
\No newline at end of file