From 5b8fc629dc23609f8de1a9d9f009835505180acb Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 16 Apr 2023 15:09:34 +0200 Subject: [PATCH] feat(lru-cache): upgrade to lru-cache v9 --- package.json | 2 +- pnpm-lock.yaml | 10 ++++++++-- src/drivers/lru-cache.ts | 26 ++++++++------------------ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 3e139829..986e1ff2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "h3": "^1.6.4", "ioredis": "^5.3.2", "listhen": "^1.0.4", - "lru-cache": "^7.18.3", + "lru-cache": "^9.0.3", "mri": "^1.2.0", "node-fetch-native": "^1.1.0", "ofetch": "^1.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c14838a..4afacb26 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,8 +20,8 @@ dependencies: specifier: ^1.0.4 version: 1.0.4 lru-cache: - specifier: ^7.18.3 - version: 7.18.3 + specifier: ^9.0.3 + version: 9.0.3 mri: specifier: ^1.2.0 version: 1.2.0 @@ -5498,6 +5498,12 @@ packages: /lru-cache@7.18.3: resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} engines: {node: '>=12'} + dev: true + + /lru-cache@9.0.3: + resolution: {integrity: sha512-cyjNRew29d4kbgnz1sjDqxg7qg8NW4s+HQzCGjeon7DV5T2yDije16W9HaUFV1dhVEMh+SjrOcK0TomBmf3Egg==} + engines: {node: 14 || >=16.14} + dev: false /magic-string@0.25.9: resolution: {integrity: sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==} diff --git a/src/drivers/lru-cache.ts b/src/drivers/lru-cache.ts index 1ad020a7..67984282 100644 --- a/src/drivers/lru-cache.ts +++ b/src/drivers/lru-cache.ts @@ -1,29 +1,19 @@ import { defineDriver } from "./utils"; -import LRU from "lru-cache"; +import { LRUCache } from "lru-cache"; -type LRUCacheOptions = LRU.SharedOptions & - // LRU.SafetyBounds - LRU.LimitedByCount & - LRU.LimitedBySize & - LRU.LimitedByTTL & { - /** - * The maximum allowed size for any single item in the cache. - * - * If a larger item is passed to set or returned by a - * fetchMethod, then it will not be stored in the cache. - */ - maxEntrySize?: number; // LRU.LRUSize - sizeCalculation?: LRU.SizeCalculator; - }; +type LRUCacheOptions = LRUCache.OptionsBase & + Partial> & + Partial> & + Partial>; -export interface LRUDriverOptions extends Partial {} +export interface LRUDriverOptions extends LRUCacheOptions {} export default defineDriver((opts: LRUDriverOptions = {}) => { - const cache = new LRU({ + const cache = new LRUCache({ max: 1000, sizeCalculation: opts.maxSize || opts.maxEntrySize - ? (value, key) => { + ? (value, key: string) => { return key.length + byteLength(value); } : undefined,