1 | var { readFileSync, writeFileSync, existsSync, writeFile } = require("fs");
|
2 | var { tmpdir } = require("os");
|
3 | var path = require("path");
|
4 | var pkg = require("./package");
|
5 |
|
6 | var cachePath = path.join(tmpdir(), `ui5_cache_${pkg.version}`);
|
7 |
|
8 | class 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 |
|
22 |
|
23 | UI5Cache.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 |
|
34 | return new UI5Cache();
|
35 | }
|
36 | };
|
37 |
|
38 | module.exports = {
|
39 | UI5Cache
|
40 | }; |
\ | No newline at end of file |