@bejibun/cache 0.1.13 → 0.1.14
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 +2 -1
- package/builders/CacheBuilder.d.ts +1 -0
- package/builders/CacheBuilder.js +28 -24
- package/config/cache.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,10 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
## [v0.1.
|
|
6
|
+
## [v0.1.14](https://github.com/crenata/bejibun-cache/compare/v0.1.12...v0.1.14) - 2025-12-12
|
|
7
7
|
|
|
8
8
|
### 🩹 Fixes
|
|
9
|
+
- Redis connection with Cache own settings - [#1](https://github.com/crenata/bejibun-core/issues/1)
|
|
9
10
|
|
|
10
11
|
### 📖 Changes
|
|
11
12
|
What's New :
|
package/builders/CacheBuilder.js
CHANGED
|
@@ -10,6 +10,7 @@ import CacheException from "../exceptions/CacheException";
|
|
|
10
10
|
export default class CacheBuilder {
|
|
11
11
|
conf;
|
|
12
12
|
prefix;
|
|
13
|
+
redis;
|
|
13
14
|
constructor() {
|
|
14
15
|
const configPath = App.Path.configPath("cache.ts");
|
|
15
16
|
let config;
|
|
@@ -17,8 +18,20 @@ export default class CacheBuilder {
|
|
|
17
18
|
config = require(configPath).default;
|
|
18
19
|
else
|
|
19
20
|
config = CacheConfig;
|
|
21
|
+
const redisConnection = defineValue(config.connections?.redis, {
|
|
22
|
+
host: "127.0.0.1",
|
|
23
|
+
port: 6379,
|
|
24
|
+
password: "",
|
|
25
|
+
database: 0
|
|
26
|
+
});
|
|
20
27
|
this.conf = config;
|
|
21
28
|
this.prefix = "bejibun-cache";
|
|
29
|
+
this.redis = Redis.setClient({
|
|
30
|
+
host: redisConnection.host,
|
|
31
|
+
port: redisConnection.port,
|
|
32
|
+
password: redisConnection.password,
|
|
33
|
+
database: redisConnection.database
|
|
34
|
+
});
|
|
22
35
|
}
|
|
23
36
|
get config() {
|
|
24
37
|
if (isEmpty(this.conf))
|
|
@@ -26,16 +39,7 @@ export default class CacheBuilder {
|
|
|
26
39
|
return this.conf;
|
|
27
40
|
}
|
|
28
41
|
key(key) {
|
|
29
|
-
|
|
30
|
-
return defaultKey;
|
|
31
|
-
/*if (forceDefault) return defaultKey;
|
|
32
|
-
|
|
33
|
-
switch (this.config.connection) {
|
|
34
|
-
case "local":
|
|
35
|
-
return `${Luxon.DateTime.now().toUnixInteger()}-${defaultKey}`;
|
|
36
|
-
default:
|
|
37
|
-
return defaultKey;
|
|
38
|
-
}*/
|
|
42
|
+
return `${this.prefix}-${key.replaceAll("/", "-").replaceAll(" ", "-")}`;
|
|
39
43
|
}
|
|
40
44
|
connection() {
|
|
41
45
|
return this.config.connections[this.config.connection];
|
|
@@ -86,10 +90,10 @@ export default class CacheBuilder {
|
|
|
86
90
|
}
|
|
87
91
|
break;
|
|
88
92
|
case "redis":
|
|
89
|
-
data = await
|
|
93
|
+
data = await this.redis.get(this.key(key));
|
|
90
94
|
if (isEmpty(data)) {
|
|
91
95
|
data = callback();
|
|
92
|
-
await
|
|
96
|
+
await this.redis.set(this.key(key), data, ttl);
|
|
93
97
|
}
|
|
94
98
|
break;
|
|
95
99
|
default:
|
|
@@ -106,7 +110,7 @@ export default class CacheBuilder {
|
|
|
106
110
|
data = raw.data;
|
|
107
111
|
break;
|
|
108
112
|
case "redis":
|
|
109
|
-
data = await
|
|
113
|
+
data = await this.redis.get(this.key(key));
|
|
110
114
|
break;
|
|
111
115
|
default:
|
|
112
116
|
data = false;
|
|
@@ -122,7 +126,7 @@ export default class CacheBuilder {
|
|
|
122
126
|
data = raw.data;
|
|
123
127
|
break;
|
|
124
128
|
case "redis":
|
|
125
|
-
data = await
|
|
129
|
+
data = await this.redis.get(this.key(key));
|
|
126
130
|
break;
|
|
127
131
|
default:
|
|
128
132
|
data = false;
|
|
@@ -140,7 +144,7 @@ export default class CacheBuilder {
|
|
|
140
144
|
data = raw.data;
|
|
141
145
|
break;
|
|
142
146
|
case "redis":
|
|
143
|
-
data = await
|
|
147
|
+
data = await this.redis.get(this.key(key));
|
|
144
148
|
break;
|
|
145
149
|
default:
|
|
146
150
|
data = null;
|
|
@@ -152,7 +156,7 @@ export default class CacheBuilder {
|
|
|
152
156
|
await this.setFile(key, value, ttl);
|
|
153
157
|
break;
|
|
154
158
|
case "redis":
|
|
155
|
-
await
|
|
159
|
+
await this.redis.set(this.key(key), value, ttl);
|
|
156
160
|
break;
|
|
157
161
|
default:
|
|
158
162
|
break;
|
|
@@ -177,7 +181,7 @@ export default class CacheBuilder {
|
|
|
177
181
|
await this.setFile(key, value, ttl);
|
|
178
182
|
break;
|
|
179
183
|
case "redis":
|
|
180
|
-
await
|
|
184
|
+
await this.redis.set(this.key(key), value, ttl);
|
|
181
185
|
break;
|
|
182
186
|
default:
|
|
183
187
|
break;
|
|
@@ -200,7 +204,7 @@ export default class CacheBuilder {
|
|
|
200
204
|
}
|
|
201
205
|
break;
|
|
202
206
|
case "redis":
|
|
203
|
-
await
|
|
207
|
+
await this.redis.del(this.key(key));
|
|
204
208
|
break;
|
|
205
209
|
default:
|
|
206
210
|
break;
|
|
@@ -222,14 +226,14 @@ export default class CacheBuilder {
|
|
|
222
226
|
}
|
|
223
227
|
break;
|
|
224
228
|
case "redis":
|
|
225
|
-
data = Number(await
|
|
229
|
+
data = Number(await this.redis.get(this.key(key)));
|
|
226
230
|
if (isEmpty(data)) {
|
|
227
231
|
data = 1;
|
|
228
|
-
await
|
|
232
|
+
await this.redis.set(this.key(key), data, ttl);
|
|
229
233
|
}
|
|
230
234
|
else {
|
|
231
235
|
data++;
|
|
232
|
-
await
|
|
236
|
+
await this.redis.set(this.key(key), data, ttl);
|
|
233
237
|
}
|
|
234
238
|
break;
|
|
235
239
|
default:
|
|
@@ -254,14 +258,14 @@ export default class CacheBuilder {
|
|
|
254
258
|
}
|
|
255
259
|
break;
|
|
256
260
|
case "redis":
|
|
257
|
-
data = Number(await
|
|
261
|
+
data = Number(await this.redis.get(this.key(key)));
|
|
258
262
|
if (isEmpty(data)) {
|
|
259
263
|
data = -1;
|
|
260
|
-
await
|
|
264
|
+
await this.redis.set(this.key(key), data, ttl);
|
|
261
265
|
}
|
|
262
266
|
else {
|
|
263
267
|
data--;
|
|
264
|
-
await
|
|
268
|
+
await this.redis.set(this.key(key), data, ttl);
|
|
265
269
|
}
|
|
266
270
|
break;
|
|
267
271
|
default:
|
package/config/cache.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/cache",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"author": "Havea Crenata <havea.crenata@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"alias": "bunx tsc-alias -p tsconfig.json",
|
|
30
30
|
"rsync": "rsync -a dist/ ./",
|
|
31
31
|
"clean": "rm -rf dist",
|
|
32
|
-
"build": "bunx tsc -p tsconfig.json && bun run alias && bun run rsync && bun run clean",
|
|
32
|
+
"build": "bun run clean && bunx tsc -p tsconfig.json && bun run alias && bun run rsync && bun run clean",
|
|
33
33
|
"deploy": "bun run build && bun publish --access public"
|
|
34
34
|
},
|
|
35
35
|
"type": "module",
|