Skip to content

Commit

Permalink
fix(nuxt-community#113): replace async-cache with lru-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dasfmi committed Feb 3, 2023
1 parent 7c8595d commit bb8b35b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
7 changes: 4 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { promisify } = require('util')
const { existsSync, mkdirSync, writeFileSync } = require('fs')
const { dirname } = require('path')
const { Feed } = require('feed')
const AsyncCache = require('async-cache')
const LRU = require('lru-cache')
const logger = require('./logger')

const defaults = {
Expand All @@ -18,8 +18,9 @@ module.exports = async function (moduleOptions) {
...await parseOptions(moduleOptions)
].map(o => ({ ...defaults, ...o }))

const feedCache = new AsyncCache({
load (feedIndex, callback) {
const feedCache = new LRU({
max: 500,
fetchMethod: async (feedIndex, callback) => {
createFeed(options[feedIndex], callback).catch(err => logger.error(err))
}
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"lib"
],
"dependencies": {
"async-cache": "^1.1.0",
"consola": "^2.12.1",
"feed": "^4.2.0"
"feed": "^4.2.0",
"lru-cache": "^7.14.1"
},
"devDependencies": {
"@commitlint/cli": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/middleware.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.mock('async-cache', () => {
jest.mock('lru-cache', () => {
return jest.fn().mockImplementation(() => {
return { get: () => { throw new Error('Error on create feed') } }
})
Expand Down
14 changes: 6 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2160,13 +2160,6 @@ astral-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==

async-cache@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/async-cache/-/async-cache-1.1.0.tgz#4a9a5a89d065ec5d8e5254bd9ee96ba76c532b5a"
integrity sha1-SppaidBl7F2OUlS9nulrp2xTK1o=
dependencies:
lru-cache "^4.0.0"

async-each@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
Expand Down Expand Up @@ -6587,7 +6580,7 @@ lower-case@^1.1.1:
resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-1.1.4.tgz#9a2cabd1b9e8e0ae993a4bf7d5875c39c42e8eac"
integrity sha1-miyr0bno4K6ZOkv31YdcOcQujqw=

lru-cache@^4.0.0, lru-cache@^4.1.2:
lru-cache@^4.1.2:
version "4.1.5"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
Expand All @@ -6602,6 +6595,11 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"

lru-cache@^7.14.1:
version "7.14.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.14.1.tgz#8da8d2f5f59827edb388e63e459ac23d6d408fea"
integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==

make-dir@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c"
Expand Down

0 comments on commit bb8b35b

Please sign in to comment.