@bejibun/cache 0.1.15 → 0.1.17
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/CHANGELOG.md +14 -0
- package/README.md +1 -0
- package/builders/CacheBuilder.js +21 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
## [v0.1.16](https://github.com/crenata/bejibun-cache/compare/v0.1.15...v0.1.16) - 2025-12-15
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
- Something went wrong when processing cache file with TTL - [#2](https://github.com/crenata/bejibun-cache/issues/2)
|
|
10
|
+
|
|
11
|
+
### 📖 Changes
|
|
12
|
+
|
|
13
|
+
### ❤️Contributors
|
|
14
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
15
|
+
|
|
16
|
+
**Full Changelog**: https://github.com/crenata/bejibun-cache/blob/master/CHANGELOG.md
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
6
20
|
## [v0.1.15](https://github.com/crenata/bejibun-cache/compare/v0.1.14...v0.1.15) - 2025-12-14
|
|
7
21
|
|
|
8
22
|
### 🩹 Fixes
|
package/README.md
CHANGED
package/builders/CacheBuilder.js
CHANGED
|
@@ -79,6 +79,9 @@ export default class CacheBuilder {
|
|
|
79
79
|
ttl = defineValue(ttl, "");
|
|
80
80
|
if (isNotEmpty(ttl))
|
|
81
81
|
ttl = Luxon.DateTime.now().toUnixInteger() + ttl;
|
|
82
|
+
const raw = await this.getFile(key);
|
|
83
|
+
if (isNotEmpty(raw.ttl))
|
|
84
|
+
ttl = Number(raw.ttl);
|
|
82
85
|
await fs.promises.mkdir(this.currentConnection.path, { recursive: true });
|
|
83
86
|
return await Bun.write(this.filePath(key), `${ttl}|${data}`);
|
|
84
87
|
}
|
|
@@ -87,19 +90,24 @@ export default class CacheBuilder {
|
|
|
87
90
|
ttl: null,
|
|
88
91
|
data: null
|
|
89
92
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
93
|
+
try {
|
|
94
|
+
const file = this.file(key);
|
|
95
|
+
if (await file.exists()) {
|
|
96
|
+
const raw = await file.text();
|
|
97
|
+
const [unix, ...rest] = raw.split("|");
|
|
98
|
+
const ttl = Number(unix);
|
|
99
|
+
const data = rest.join("|");
|
|
100
|
+
if (isEmpty(ttl) || Luxon.DateTime.now().toUnixInteger() <= ttl)
|
|
101
|
+
metadata = {
|
|
102
|
+
ttl: defineValue(Number(ttl)),
|
|
103
|
+
data
|
|
104
|
+
};
|
|
105
|
+
else
|
|
106
|
+
await file.delete();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
Logger.setContext("Cache").error("Something went wrong when processing cache file.").trace(error);
|
|
103
111
|
}
|
|
104
112
|
return metadata;
|
|
105
113
|
}
|