@platformatic/next 2.24.0 → 2.25.0
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 +35 -2
- package/package.json +6 -6
- package/schema.json +1 -1
package/lib/caching/valkey.js
CHANGED
|
@@ -7,6 +7,11 @@ import { resolve } from 'node:path'
|
|
|
7
7
|
import { fileURLToPath } from 'node:url'
|
|
8
8
|
import { pino } from 'pino'
|
|
9
9
|
|
|
10
|
+
const CACHE_HIT_METRIC = { name: 'next_cache_valkey_hit_count', help: 'Next.js Cache (Valkey) Hit Count' }
|
|
11
|
+
const CACHE_MISS_METRIC = { name: 'next_cache_valkey_miss_count', help: 'Next.js Cache (Valkey) Miss Count' }
|
|
12
|
+
|
|
13
|
+
const clients = new Map()
|
|
14
|
+
|
|
10
15
|
export const MAX_BATCH_SIZE = 100
|
|
11
16
|
|
|
12
17
|
export const sections = {
|
|
@@ -14,8 +19,6 @@ export const sections = {
|
|
|
14
19
|
tags: 'tags'
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
const clients = new Map()
|
|
18
|
-
|
|
19
22
|
export function keyFor (prefix, subprefix, section, key) {
|
|
20
23
|
return [prefix, 'cache:next', subprefix, section, key ? Buffer.from(key).toString('base64url') : undefined]
|
|
21
24
|
.filter(c => c)
|
|
@@ -46,6 +49,8 @@ export class CacheHandler {
|
|
|
46
49
|
#subprefix
|
|
47
50
|
#meta
|
|
48
51
|
#maxTTL
|
|
52
|
+
#cacheHitMetric
|
|
53
|
+
#cacheMissMetric
|
|
49
54
|
|
|
50
55
|
constructor (options) {
|
|
51
56
|
options ??= {}
|
|
@@ -86,6 +91,10 @@ export class CacheHandler {
|
|
|
86
91
|
if (!this.#store) {
|
|
87
92
|
throw new Error('Please provide a the "store" option.')
|
|
88
93
|
}
|
|
94
|
+
|
|
95
|
+
if (globalThis.platformatic) {
|
|
96
|
+
this.#registerMetrics()
|
|
97
|
+
}
|
|
89
98
|
}
|
|
90
99
|
|
|
91
100
|
async get (cacheKey, _, isRedisKey) {
|
|
@@ -98,9 +107,11 @@ export class CacheHandler {
|
|
|
98
107
|
rawValue = await this.#store.get(key)
|
|
99
108
|
|
|
100
109
|
if (!rawValue) {
|
|
110
|
+
this.#cacheMissMetric?.inc()
|
|
101
111
|
return
|
|
102
112
|
}
|
|
103
113
|
} catch (e) {
|
|
114
|
+
this.#cacheMissMetric?.inc()
|
|
104
115
|
this.#logger.error({ err: ensureLoggableError(e) }, 'Cannot read cache value from Valkey')
|
|
105
116
|
throw new Error('Cannot read cache value from Valkey', { cause: e })
|
|
106
117
|
}
|
|
@@ -109,6 +120,7 @@ export class CacheHandler {
|
|
|
109
120
|
try {
|
|
110
121
|
value = this.#deserialize(rawValue)
|
|
111
122
|
} catch (e) {
|
|
123
|
+
this.#cacheMissMetric?.inc()
|
|
112
124
|
this.#logger.error({ err: ensureLoggableError(e) }, 'Cannot deserialize cache value from Valkey')
|
|
113
125
|
|
|
114
126
|
// Avoid useless reads the next time
|
|
@@ -129,6 +141,7 @@ export class CacheHandler {
|
|
|
129
141
|
}
|
|
130
142
|
}
|
|
131
143
|
|
|
144
|
+
this.#cacheHitMetric?.inc()
|
|
132
145
|
return value
|
|
133
146
|
}
|
|
134
147
|
|
|
@@ -325,6 +338,26 @@ export class CacheHandler {
|
|
|
325
338
|
#deserialize (data) {
|
|
326
339
|
return unpack(Buffer.from(data, 'base64url'))
|
|
327
340
|
}
|
|
341
|
+
|
|
342
|
+
#registerMetrics () {
|
|
343
|
+
const { client, registry } = globalThis.platformatic.prometheus
|
|
344
|
+
|
|
345
|
+
this.#cacheHitMetric =
|
|
346
|
+
registry.getSingleMetric(CACHE_HIT_METRIC.name) ??
|
|
347
|
+
new client.Counter({
|
|
348
|
+
name: CACHE_HIT_METRIC.name,
|
|
349
|
+
help: CACHE_HIT_METRIC.help,
|
|
350
|
+
registers: [registry]
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
this.#cacheMissMetric =
|
|
354
|
+
registry.getSingleMetric(CACHE_MISS_METRIC.name) ??
|
|
355
|
+
new client.Counter({
|
|
356
|
+
name: CACHE_MISS_METRIC.name,
|
|
357
|
+
help: CACHE_MISS_METRIC.help,
|
|
358
|
+
registers: [registry]
|
|
359
|
+
})
|
|
360
|
+
}
|
|
328
361
|
}
|
|
329
362
|
|
|
330
363
|
export default CacheHandler
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/next",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.0",
|
|
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.
|
|
27
|
-
"@platformatic/utils": "2.
|
|
28
|
-
"@platformatic/config": "2.
|
|
26
|
+
"@platformatic/basic": "2.25.0",
|
|
27
|
+
"@platformatic/utils": "2.25.0",
|
|
28
|
+
"@platformatic/config": "2.25.0"
|
|
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.
|
|
45
|
-
"@platformatic/service": "2.
|
|
44
|
+
"@platformatic/composer": "2.25.0",
|
|
45
|
+
"@platformatic/service": "2.25.0"
|
|
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.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/next/2.25.0.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"title": "Platformatic Next.js Stackable",
|
|
5
5
|
"type": "object",
|