@griddo/cx 1.72.6 → 1.72.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gatsby-config.js +1 -0
- package/package.json +3 -3
- package/src/utils/cache.js +29 -25
package/gatsby-config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/cx",
|
|
3
3
|
"description": "Griddo SSG based on Gatsby",
|
|
4
|
-
"version": "1.72.
|
|
4
|
+
"version": "1.72.7",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Carlos Torres <carlos.torres@secuoyas.com>",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"react-helmet": "^6.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@griddo/eslint-config-back": "^1.72.
|
|
68
|
+
"@griddo/eslint-config-back": "^1.72.7",
|
|
69
69
|
"eslint": "^7.5.0",
|
|
70
70
|
"eslint-plugin-node": "^11.1.0",
|
|
71
71
|
"eslint-plugin-react": "7.14.3",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"publishConfig": {
|
|
98
98
|
"access": "public"
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "560fef6f6b478792274a9c4cb76ccb748aa3bab0"
|
|
101
101
|
}
|
package/src/utils/cache.js
CHANGED
|
@@ -3,40 +3,44 @@ const path = require('path');
|
|
|
3
3
|
const crypto = require('crypto');
|
|
4
4
|
|
|
5
5
|
const apiCacheDirectory = './apiCache';
|
|
6
|
+
const gatsbyCacheDirectory = path.resolve(__dirname, './../../.cache');
|
|
6
7
|
|
|
7
8
|
const initCache = () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
// TODO: Make a domain-based cache to store and restore
|
|
10
|
+
if (fs.existsSync(gatsbyCacheDirectory)) {
|
|
11
|
+
fs.rmdirSync(gatsbyCacheDirectory, {
|
|
12
|
+
force: true,
|
|
13
|
+
recursive: true,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (!fs.existsSync(apiCacheDirectory)) {
|
|
17
|
+
fs.mkdirSync(apiCacheDirectory);
|
|
18
|
+
}
|
|
16
19
|
};
|
|
17
20
|
|
|
18
|
-
const generateFilename =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const generateFilename = petition => {
|
|
22
|
+
const hashSum = crypto.createHash('sha256');
|
|
23
|
+
hashSum.update(JSON.stringify(petition));
|
|
24
|
+
return `${apiCacheDirectory}/${hashSum.digest('hex')}`;
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
const saveCache = (petition, content = '') => {
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
const rightContent =
|
|
29
|
+
typeof content === 'object' ? JSON.stringify(content) : content;
|
|
30
|
+
fs.writeFileSync(generateFilename(petition), rightContent, 'utf8');
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
const getCache =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const getCache = petition => {
|
|
34
|
+
try {
|
|
35
|
+
const content = fs.readFileSync(generateFilename(petition));
|
|
36
|
+
return JSON.parse(content);
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
36
40
|
};
|
|
37
41
|
|
|
38
42
|
module.exports = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
+
initCache,
|
|
44
|
+
saveCache,
|
|
45
|
+
getCache,
|
|
46
|
+
};
|