3a2d50c1 by Adam Heath

Switch from node-cache to @isaacs/ttlcache, which works in the browser.

1 parent 8a5e8d74
import NodeCache from 'node-cache'
import TTLCache from '@isaacs/ttlcache'
export const selectorCache = new NodeCache({
stdTTL: 10*60,
useClones: false,
export const selectorCache = new TTLCache({
ttl: 10*60,
})
export const parsedHtmlCache = new NodeCache({
stdTTL: 10*60,
useClones: false,
export const parsedHtmlCache = new TTLCache({
ttl: 10*60,
})
export const findNodeCache = new WeakMap()
......
import nodeUtil from 'util'
import NodeCache from 'node-cache'
import TTLCache from '@isaacs/ttlcache'
import type { NodeType } from 'ultrahtml'
import {
......@@ -319,7 +319,7 @@ export const findNode = (doc: NodeType, selector: string): NodeType => {
if (!selector) return doc
let docCache = findNodeCache.get(doc)
if (!docCache) {
docCache = new NodeCache({ stdTTL: 10*60, useClones: false })
docCache = new TTLCache({ ttl: 10*60 })
findNodeCache.set(doc, docCache)
}
const found = docCache.get(selector)
......
......@@ -6,8 +6,8 @@
"": {
"name": "astro-wt",
"dependencies": {
"@isaacs/ttlcache": "^1.4.1",
"@reduxjs/toolkit": "^2.2.5",
"node-cache": "^5.1.2",
"parsel-js": "^1.1.2",
"ultrahtml": "^1.5.3"
},
......@@ -1351,6 +1351,14 @@
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@isaacs/ttlcache": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz",
"integrity": "sha512-RQgQ4uQ+pLbqXfOmieB91ejmLwvSgv9nLx6sT6sD83s7umBypgg+OIBOBbEUiJXrfpnp9j0mRhYYdzp9uqq3lA==",
"engines": {
"node": ">=12"
}
},
"node_modules/@jridgewell/gen-mapping": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz",
......@@ -2339,14 +2347,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/clone": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
"integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==",
"engines": {
"node": ">=0.8"
}
},
"node_modules/clsx": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
......@@ -4575,17 +4575,6 @@
"url": "https://opencollective.com/unified"
}
},
"node_modules/node-cache": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz",
"integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==",
"dependencies": {
"clone": "2.x"
},
"engines": {
"node": ">= 8.0.0"
}
},
"node_modules/node-releases": {
"version": "2.0.14",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz",
......
......@@ -10,8 +10,8 @@
"dev": "astro dev"
},
"dependencies": {
"@isaacs/ttlcache": "^1.4.1",
"@reduxjs/toolkit": "^2.2.5",
"node-cache": "^5.1.2",
"parsel-js": "^1.1.2",
"ultrahtml": "^1.5.3"
},
......