@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 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
@@ -71,6 +71,7 @@ How to use tha package.
71
71
  ```ts
72
72
  import Cache from "@bejibun/cache";
73
73
 
74
+ Cache.connection();
74
75
  await Cache.remember("key", () => {}, 60 /* seconds */); // any
75
76
  await Cache.has("key"); // boolean
76
77
  await Cache.get("key"); // any
@@ -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
- const file = this.file(key);
91
- if (await file.exists()) {
92
- const raw = await file.text();
93
- const [unix, ...rest] = raw.split("|");
94
- const ttl = Number(unix);
95
- const data = rest.join("|");
96
- if (isEmpty(ttl) || Luxon.DateTime.now().toUnixInteger() <= ttl)
97
- metadata = {
98
- ttl: defineValue(Number(ttl)),
99
- data
100
- };
101
- else
102
- await this.file(key).delete();
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/cache",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",