Switch from node-cache to @isaacs/ttlcache, which works in the browser.
Showing
4 changed files
with
17 additions
and
30 deletions
1 | import NodeCache from 'node-cache' | 1 | import TTLCache from '@isaacs/ttlcache' |
2 | 2 | ||
3 | export const selectorCache = new NodeCache({ | 3 | export const selectorCache = new TTLCache({ |
4 | stdTTL: 10*60, | 4 | ttl: 10*60, |
5 | useClones: false, | ||
6 | }) | 5 | }) |
7 | 6 | ||
8 | export const parsedHtmlCache = new NodeCache({ | 7 | export const parsedHtmlCache = new TTLCache({ |
9 | stdTTL: 10*60, | 8 | ttl: 10*60, |
10 | useClones: false, | ||
11 | }) | 9 | }) |
12 | 10 | ||
13 | export const findNodeCache = new WeakMap() | 11 | export const findNodeCache = new WeakMap() | ... | ... |
1 | import nodeUtil from 'util' | 1 | import nodeUtil from 'util' |
2 | import NodeCache from 'node-cache' | 2 | import TTLCache from '@isaacs/ttlcache' |
3 | 3 | ||
4 | import type { NodeType } from 'ultrahtml' | 4 | import type { NodeType } from 'ultrahtml' |
5 | import { | 5 | import { |
... | @@ -319,7 +319,7 @@ export const findNode = (doc: NodeType, selector: string): NodeType => { | ... | @@ -319,7 +319,7 @@ export const findNode = (doc: NodeType, selector: string): NodeType => { |
319 | if (!selector) return doc | 319 | if (!selector) return doc |
320 | let docCache = findNodeCache.get(doc) | 320 | let docCache = findNodeCache.get(doc) |
321 | if (!docCache) { | 321 | if (!docCache) { |
322 | docCache = new NodeCache({ stdTTL: 10*60, useClones: false }) | 322 | docCache = new TTLCache({ ttl: 10*60 }) |
323 | findNodeCache.set(doc, docCache) | 323 | findNodeCache.set(doc, docCache) |
324 | } | 324 | } |
325 | const found = docCache.get(selector) | 325 | const found = docCache.get(selector) | ... | ... |
... | @@ -6,8 +6,8 @@ | ... | @@ -6,8 +6,8 @@ |
6 | "": { | 6 | "": { |
7 | "name": "astro-wt", | 7 | "name": "astro-wt", |
8 | "dependencies": { | 8 | "dependencies": { |
9 | "@isaacs/ttlcache": "^1.4.1", | ||
9 | "@reduxjs/toolkit": "^2.2.5", | 10 | "@reduxjs/toolkit": "^2.2.5", |
10 | "node-cache": "^5.1.2", | ||
11 | "parsel-js": "^1.1.2", | 11 | "parsel-js": "^1.1.2", |
12 | "ultrahtml": "^1.5.3" | 12 | "ultrahtml": "^1.5.3" |
13 | }, | 13 | }, |
... | @@ -1351,6 +1351,14 @@ | ... | @@ -1351,6 +1351,14 @@ |
1351 | "url": "https://opencollective.com/libvips" | 1351 | "url": "https://opencollective.com/libvips" |
1352 | } | 1352 | } |
1353 | }, | 1353 | }, |
1354 | "node_modules/@isaacs/ttlcache": { | ||
1355 | "version": "1.4.1", | ||
1356 | "resolved": "https://registry.npmjs.org/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz", | ||
1357 | "integrity": "sha512-RQgQ4uQ+pLbqXfOmieB91ejmLwvSgv9nLx6sT6sD83s7umBypgg+OIBOBbEUiJXrfpnp9j0mRhYYdzp9uqq3lA==", | ||
1358 | "engines": { | ||
1359 | "node": ">=12" | ||
1360 | } | ||
1361 | }, | ||
1354 | "node_modules/@jridgewell/gen-mapping": { | 1362 | "node_modules/@jridgewell/gen-mapping": { |
1355 | "version": "0.3.5", | 1363 | "version": "0.3.5", |
1356 | "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", | 1364 | "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", |
... | @@ -2339,14 +2347,6 @@ | ... | @@ -2339,14 +2347,6 @@ |
2339 | "url": "https://github.com/sponsors/sindresorhus" | 2347 | "url": "https://github.com/sponsors/sindresorhus" |
2340 | } | 2348 | } |
2341 | }, | 2349 | }, |
2342 | "node_modules/clone": { | ||
2343 | "version": "2.1.2", | ||
2344 | "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", | ||
2345 | "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", | ||
2346 | "engines": { | ||
2347 | "node": ">=0.8" | ||
2348 | } | ||
2349 | }, | ||
2350 | "node_modules/clsx": { | 2350 | "node_modules/clsx": { |
2351 | "version": "2.1.1", | 2351 | "version": "2.1.1", |
2352 | "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", | 2352 | "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", |
... | @@ -4575,17 +4575,6 @@ | ... | @@ -4575,17 +4575,6 @@ |
4575 | "url": "https://opencollective.com/unified" | 4575 | "url": "https://opencollective.com/unified" |
4576 | } | 4576 | } |
4577 | }, | 4577 | }, |
4578 | "node_modules/node-cache": { | ||
4579 | "version": "5.1.2", | ||
4580 | "resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz", | ||
4581 | "integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==", | ||
4582 | "dependencies": { | ||
4583 | "clone": "2.x" | ||
4584 | }, | ||
4585 | "engines": { | ||
4586 | "node": ">= 8.0.0" | ||
4587 | } | ||
4588 | }, | ||
4589 | "node_modules/node-releases": { | 4578 | "node_modules/node-releases": { |
4590 | "version": "2.0.14", | 4579 | "version": "2.0.14", |
4591 | "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", | 4580 | "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", | ... | ... |
... | @@ -10,8 +10,8 @@ | ... | @@ -10,8 +10,8 @@ |
10 | "dev": "astro dev" | 10 | "dev": "astro dev" |
11 | }, | 11 | }, |
12 | "dependencies": { | 12 | "dependencies": { |
13 | "@isaacs/ttlcache": "^1.4.1", | ||
13 | "@reduxjs/toolkit": "^2.2.5", | 14 | "@reduxjs/toolkit": "^2.2.5", |
14 | "node-cache": "^5.1.2", | ||
15 | "parsel-js": "^1.1.2", | 15 | "parsel-js": "^1.1.2", |
16 | "ultrahtml": "^1.5.3" | 16 | "ultrahtml": "^1.5.3" |
17 | }, | 17 | }, | ... | ... |
-
Please register or sign in to post a comment