|
2 | 2 | var fs = require('fs'); |
3 | 3 | var path = require('path'); |
4 | 4 |
|
5 | | -var h = require('./helper'); |
| 5 | +var file = require('./file'); |
6 | 6 |
|
7 | 7 | const cache = {}; |
8 | 8 |
|
9 | 9 | cache.init = function() { |
10 | | - h.mkdir(h.getCacheDir()); |
| 10 | + file.mkdir(file.cacheDir()); |
11 | 11 | }; |
12 | 12 |
|
13 | 13 | cache.get = function(k) { |
14 | | - const fullpath = h.getCacheFile(k); |
| 14 | + const fullpath = file.cacheFile(k); |
15 | 15 | if (!fs.existsSync(fullpath)) return null; |
16 | 16 |
|
17 | 17 | return JSON.parse(fs.readFileSync(fullpath)); |
18 | 18 | }; |
19 | 19 |
|
20 | 20 | cache.set = function(k, v) { |
21 | | - const fullpath = h.getCacheFile(k); |
| 21 | + const fullpath = file.cacheFile(k); |
22 | 22 | fs.writeFileSync(fullpath, JSON.stringify(v)); |
23 | 23 | return true; |
24 | 24 | }; |
25 | 25 |
|
26 | 26 | cache.del = function(k) { |
27 | | - const fullpath = h.getCacheFile(k); |
| 27 | + const fullpath = file.cacheFile(k); |
28 | 28 | if (!fs.existsSync(fullpath)) return false; |
29 | 29 |
|
30 | 30 | fs.unlinkSync(fullpath); |
31 | 31 | return true; |
32 | 32 | }; |
33 | 33 |
|
34 | 34 | cache.list = function() { |
35 | | - return fs.readdirSync(h.getCacheDir()) |
| 35 | + return file.list(file.cacheDir()) |
36 | 36 | .filter(x => path.extname(x) === '.json') |
37 | 37 | .map(function(filename) { |
38 | 38 | const k = path.basename(filename, '.json'); |
39 | | - const stat = fs.statSync(h.getCacheFile(k)); |
| 39 | + const stat = fs.statSync(file.cacheFile(k)); |
40 | 40 | return { |
41 | 41 | name: k, |
42 | 42 | size: stat.size, |
|
0 commit comments