@platformatic/next 2.21.0-alpha.1 → 2.21.0-alpha.2
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/lib/caching/valkey.js +47 -10
- package/package.json +6 -6
- package/schema.json +1 -1
package/lib/caching/valkey.js
CHANGED
|
@@ -42,24 +42,47 @@ export class CacheHandler {
|
|
|
42
42
|
#logger
|
|
43
43
|
#store
|
|
44
44
|
#subprefix
|
|
45
|
+
#meta
|
|
45
46
|
#maxTTL
|
|
46
47
|
|
|
47
48
|
constructor (options) {
|
|
48
49
|
options ??= {}
|
|
49
50
|
|
|
50
|
-
this.#config = options.config
|
|
51
|
+
this.#config = options.config
|
|
52
|
+
this.#logger = options.logger
|
|
53
|
+
this.#store = options.store
|
|
54
|
+
this.#maxTTL = options.maxTTL
|
|
55
|
+
this.#subprefix = options.subprefix
|
|
56
|
+
this.#meta = options.meta
|
|
57
|
+
|
|
58
|
+
if (globalThis.platformatic) {
|
|
59
|
+
this.#config ??= globalThis.platformatic.config.cache
|
|
60
|
+
this.#logger ??= this.#createPlatformaticLogger()
|
|
61
|
+
this.#store ??= getConnection(this.#config.url)
|
|
62
|
+
this.#maxTTL ??= this.#config.maxTTL
|
|
63
|
+
this.#subprefix ??= this.#getPlatformaticSubprefix()
|
|
64
|
+
this.#meta ??= this.#getPlatformaticMeta()
|
|
65
|
+
} else {
|
|
66
|
+
this.#config ??= {}
|
|
67
|
+
this.#maxTTL ??= 86_400
|
|
68
|
+
this.#subprefix ??= ''
|
|
69
|
+
this.#meta ??= {}
|
|
70
|
+
}
|
|
51
71
|
|
|
52
72
|
if (!this.#config) {
|
|
53
|
-
throw new Error('Please provide a
|
|
73
|
+
throw new Error('Please provide a the "config" option.')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!this.#logger) {
|
|
77
|
+
throw new Error('Please provide a the "logger" option.')
|
|
54
78
|
}
|
|
55
79
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.#subprefix = options.subprefix ?? this.#getSubprefix()
|
|
80
|
+
if (!this.#store) {
|
|
81
|
+
throw new Error('Please provide a the "store" option.')
|
|
82
|
+
}
|
|
60
83
|
}
|
|
61
84
|
|
|
62
|
-
async get (cacheKey, isRedisKey) {
|
|
85
|
+
async get (cacheKey, _, isRedisKey) {
|
|
63
86
|
this.#logger.trace({ key: cacheKey }, 'get')
|
|
64
87
|
|
|
65
88
|
const key = isRedisKey ? cacheKey : this.#keyFor(cacheKey, sections.values)
|
|
@@ -110,7 +133,14 @@ export class CacheHandler {
|
|
|
110
133
|
|
|
111
134
|
try {
|
|
112
135
|
// Compute the parameters to save
|
|
113
|
-
const data = this.#serialize({
|
|
136
|
+
const data = this.#serialize({
|
|
137
|
+
value,
|
|
138
|
+
tags,
|
|
139
|
+
lastModified: Date.now(),
|
|
140
|
+
revalidate,
|
|
141
|
+
maxTTL: this.#maxTTL,
|
|
142
|
+
...this.#meta
|
|
143
|
+
})
|
|
114
144
|
const expire = Math.min(revalidate, this.#maxTTL)
|
|
115
145
|
|
|
116
146
|
if (expire < 1) {
|
|
@@ -247,7 +277,7 @@ export class CacheHandler {
|
|
|
247
277
|
await Promise.all(promises)
|
|
248
278
|
}
|
|
249
279
|
|
|
250
|
-
#
|
|
280
|
+
#createPlatformaticLogger () {
|
|
251
281
|
const pinoOptions = {
|
|
252
282
|
level: globalThis.platformatic?.logLevel ?? 'info'
|
|
253
283
|
}
|
|
@@ -263,7 +293,7 @@ export class CacheHandler {
|
|
|
263
293
|
return pino(pinoOptions)
|
|
264
294
|
}
|
|
265
295
|
|
|
266
|
-
#
|
|
296
|
+
#getPlatformaticSubprefix () {
|
|
267
297
|
const root = fileURLToPath(globalThis.platformatic.root)
|
|
268
298
|
|
|
269
299
|
return existsSync(resolve(root, '.next/BUILD_ID'))
|
|
@@ -271,6 +301,13 @@ export class CacheHandler {
|
|
|
271
301
|
: 'development'
|
|
272
302
|
}
|
|
273
303
|
|
|
304
|
+
#getPlatformaticMeta () {
|
|
305
|
+
return {
|
|
306
|
+
serviceId: globalThis.platformatic.serviceId,
|
|
307
|
+
workerId: globalThis.platformatic.workerId
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
274
311
|
#keyFor (key, section) {
|
|
275
312
|
return keyFor(this.#config.prefix, this.#subprefix, section, key)
|
|
276
313
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/next",
|
|
3
|
-
"version": "2.21.0-alpha.
|
|
3
|
+
"version": "2.21.0-alpha.2",
|
|
4
4
|
"description": "Platformatic Next.js Stackable",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"iovalkey": "^0.2.1",
|
|
24
24
|
"msgpackr": "^1.11.2",
|
|
25
25
|
"semver": "^7.6.3",
|
|
26
|
-
"@platformatic/basic": "2.21.0-alpha.
|
|
27
|
-
"@platformatic/
|
|
28
|
-
"@platformatic/
|
|
26
|
+
"@platformatic/basic": "2.21.0-alpha.2",
|
|
27
|
+
"@platformatic/utils": "2.21.0-alpha.2",
|
|
28
|
+
"@platformatic/config": "2.21.0-alpha.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@fastify/reply-from": "^11.0.0",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"react-dom": "^18.3.1",
|
|
42
42
|
"typescript": "^5.5.4",
|
|
43
43
|
"ws": "^8.18.0",
|
|
44
|
-
"@platformatic/composer": "2.21.0-alpha.
|
|
45
|
-
"@platformatic/service": "2.21.0-alpha.
|
|
44
|
+
"@platformatic/composer": "2.21.0-alpha.2",
|
|
45
|
+
"@platformatic/service": "2.21.0-alpha.2"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"test": "npm run lint && borp --concurrency=1 --no-timeout",
|
package/schema.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/next/2.21.0-alpha.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/next/2.21.0-alpha.2.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"title": "Platformatic Next.js Stackable",
|
|
5
5
|
"type": "object",
|