@platformatic/next 2.19.0-alpha.1 → 2.19.0-alpha.3

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.
@@ -14,12 +14,29 @@ const sections = {
14
14
  tags: 'tags'
15
15
  }
16
16
 
17
+ const clients = new Map()
18
+
17
19
  export function keyFor (prefix, subprefix, section, key) {
18
20
  return [prefix, 'cache:next', subprefix, section, key ? Buffer.from(key).toString('base64url') : undefined]
19
21
  .filter(c => c)
20
22
  .join(':')
21
23
  }
22
24
 
25
+ export function getConnection (url) {
26
+ let client = clients.get(url)
27
+
28
+ if (!client) {
29
+ client = new Redis(url, { enableAutoPipelining: true })
30
+ clients.set(url, client)
31
+
32
+ globalThis.platformatic.events.on('plt:next:close', () => {
33
+ client.disconnect(false)
34
+ })
35
+ }
36
+
37
+ return client
38
+ }
39
+
23
40
  export class CacheHandler {
24
41
  #config
25
42
  #logger
@@ -30,14 +47,9 @@ export class CacheHandler {
30
47
  constructor () {
31
48
  this.#logger = this.#createLogger()
32
49
  this.#config = globalThis.platformatic.config.cache
33
- this.#store = new Redis(this.#config.url, { enableAutoPipelining: true })
50
+ this.#store = getConnection(this.#config.url)
34
51
  this.#maxTTL = this.#config.maxTTL
35
52
  this.#subprefix = this.#getSubprefix()
36
-
37
- // Handle disconnection not to hang the process on exit
38
- globalThis.platformatic.events.on('plt:next:close', () => {
39
- this.#store.disconnect(false)
40
- })
41
53
  }
42
54
 
43
55
  async get (cacheKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/next",
3
- "version": "2.19.0-alpha.1",
3
+ "version": "2.19.0-alpha.3",
4
4
  "description": "Platformatic Next.js Stackable",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -22,9 +22,9 @@
22
22
  "iovalkey": "^0.2.1",
23
23
  "msgpackr": "^1.11.2",
24
24
  "semver": "^7.6.3",
25
- "@platformatic/basic": "2.19.0-alpha.1",
26
- "@platformatic/config": "2.19.0-alpha.1",
27
- "@platformatic/utils": "2.19.0-alpha.1"
25
+ "@platformatic/basic": "2.19.0-alpha.3",
26
+ "@platformatic/config": "2.19.0-alpha.3",
27
+ "@platformatic/utils": "2.19.0-alpha.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@fastify/reply-from": "^11.0.0",
@@ -38,8 +38,8 @@
38
38
  "react-dom": "^18.3.1",
39
39
  "typescript": "^5.5.4",
40
40
  "ws": "^8.18.0",
41
- "@platformatic/composer": "2.19.0-alpha.1",
42
- "@platformatic/service": "2.19.0-alpha.1"
41
+ "@platformatic/composer": "2.19.0-alpha.3",
42
+ "@platformatic/service": "2.19.0-alpha.3"
43
43
  },
44
44
  "scripts": {
45
45
  "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.19.0-alpha.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/next/2.19.0-alpha.3.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Next.js Stackable",
5
5
  "type": "object",