From 156c712aaba8ee365f66edc046577672b1c1453a Mon Sep 17 00:00:00 2001 From: Kalil Smith-Nuevelle Date: Wed, 30 Apr 2025 09:02:13 -0500 Subject: [PATCH] Revert "Add valkey cache handler to next app (#1210)" This reverts commit 32bd4077502e703b4c396a86f8dc5e71ce24719c. --- core/.env.development | 2 +- core/cache-handler.mjs | 95 +++-------------------- core/instrumentation.node.mts | 5 -- core/package.json | 3 - docker-compose.dev.yml | 2 - package.json | 2 - pnpm-lock.yaml | 139 ++-------------------------------- 7 files changed, 15 insertions(+), 233 deletions(-) diff --git a/core/.env.development b/core/.env.development index 8fb25f5443..fc87fb9514 100644 --- a/core/.env.development +++ b/core/.env.development @@ -25,4 +25,4 @@ DATACITE_PASSWORD="" DATACITE_API_URL="https://api.test.datacite.org" GCLOUD_KEY_FILE='xxx' -VALKEY_URL='redis://localhost:6379' \ No newline at end of file +VALKEY_URL='redis://cache:6379' \ No newline at end of file diff --git a/core/cache-handler.mjs b/core/cache-handler.mjs index 0d1c477c4f..ea52f41d35 100644 --- a/core/cache-handler.mjs +++ b/core/cache-handler.mjs @@ -1,88 +1,11 @@ -// Based on https://github.com/fortedigital/nextjs-cache-handler#full-example +/** + * Solution taken from here: https://github.com/vercel/next.js/discussions/48324#discussioncomment-10542097 + * + * We are reexporting `next.js`'s default cache handler to get around + * the fixed 2mb limit for cached fetches. + * We run into this limit somewhat quickly if we fetch more than 100 pubs. + */ -import { PHASE_PRODUCTION_BUILD } from "next/constants.js"; -import createBufferStringHandler from "@fortedigital/nextjs-cache-handler/buffer-string-decorator"; -import { Next15CacheHandler } from "@fortedigital/nextjs-cache-handler/next-15-cache-handler"; -import createRedisHandler from "@fortedigital/nextjs-cache-handler/redis-strings"; -import { CacheHandler } from "@neshca/cache-handler"; -import createLruHandler from "@neshca/cache-handler/local-lru"; -import { createClient } from "redis"; +import FileSystemCache from "next/dist/server/lib/incremental-cache/file-system-cache.js"; -// Usual onCreation from @neshca/cache-handler -CacheHandler.onCreation(() => { - // Important - It's recommended to use global scope to ensure only one Redis connection is made - // This ensures only one instance get created - if (global.cacheHandlerConfig) { - return global.cacheHandlerConfig; - } - - // Important - It's recommended to use global scope to ensure only one Redis connection is made - // This ensures new instances are not created in a race condition - if (global.cacheHandlerConfigPromise) { - return global.cacheHandlerConfigPromise; - } - - // Main promise initializing the handler - global.cacheHandlerConfigPromise = (async () => { - /** @type {import("redis").RedisClientType | null} */ - let redisClient = null; - if (PHASE_PRODUCTION_BUILD !== process.env.NEXT_PHASE) { - try { - redisClient = createClient({ - url: process.env.VALKEY_URL, - pingInterval: 10000, - }); - redisClient.on("error", (e) => { - if (typeof process.env.NEXT_PRIVATE_DEBUG_CACHE !== "undefined") { - console.warn("Redis error", e); - } - global.cacheHandlerConfig = null; - global.cacheHandlerConfigPromise = null; - }); - } catch (error) { - console.warn("Failed to create Redis client:", error); - } - } - - if (redisClient) { - try { - console.info("Connecting Redis client..."); - await redisClient.connect(); - console.info("Redis client connected."); - } catch (error) { - console.warn("Failed to connect Redis client:", error); - await redisClient - .disconnect() - .catch(() => - console.warn("Failed to quit the Redis client after failing to connect.") - ); - } - } - const lruCache = createLruHandler(); - - if (!redisClient?.isReady) { - console.error("Failed to initialize caching layer."); - global.cacheHandlerConfigPromise = null; - global.cacheHandlerConfig = { handlers: [lruCache] }; - return global.cacheHandlerConfig; - } - - const redisCacheHandler = createRedisHandler({ - client: redisClient, - keyPrefix: "nextjs:", - keyExpirationStrategy: "EXAT", - }); - - global.cacheHandlerConfigPromise = null; - - global.cacheHandlerConfig = { - handlers: [createBufferStringHandler(redisCacheHandler)], - }; - - return global.cacheHandlerConfig; - })(); - - return global.cacheHandlerConfigPromise; -}); - -export default new Next15CacheHandler(); +export default FileSystemCache; diff --git a/core/instrumentation.node.mts b/core/instrumentation.node.mts index 3efb12f679..56f33a1524 100644 --- a/core/instrumentation.node.mts +++ b/core/instrumentation.node.mts @@ -19,11 +19,6 @@ if (env.NODE_ENV === "production") { // Setting this option to true will print useful information to the console while you're setting up Sentry. debug: false, - integrations: [ - Sentry.redisIntegration({ - cachePrefixes: ["nextjs:"], - }), - ], }); logger.info("✅ Successfully instrumented Sentry"); } diff --git a/core/package.json b/core/package.json index a27db56d05..2382dfa78a 100644 --- a/core/package.json +++ b/core/package.json @@ -62,13 +62,11 @@ "@dnd-kit/sortable": "^8.0.0", "@dnd-kit/utilities": "^3.2.2", "@faker-js/faker": "^9.0.0", - "@fortedigital/nextjs-cache-handler": "^1.2.0", "@googleapis/drive": "^8.16.0", "@handlewithcare/react-prosemirror": "catalog:", "@honeycombio/opentelemetry-node": "catalog:", "@hookform/resolvers": "catalog:", "@icons-pack/react-simple-icons": "^10.2.0", - "@neshca/cache-handler": "^1.9.0", "@nimpl/getters": "^2.0.0", "@node-rs/argon2": "^1.8.3", "@opentelemetry/auto-instrumentations-node": "catalog:", @@ -127,7 +125,6 @@ "react-hook-form": "catalog:", "react-markdown": "^9.0.1", "reactflow": "^11.10.4", - "redis": "^4.7.0", "rehype": "^13.0.2", "rehype-format": "^5.0.0", "rehype-parse": "^9.0.1", diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index ed6bc530b6..8d9843816f 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -45,8 +45,6 @@ services: service: cache networks: - app-network - ports: - - 6379:6379 minio-init: env_file: diff --git a/package.json b/package.json index 7edaf9ab9c..3f8466deee 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,6 @@ "dev:inbucket:stop": "docker compose -f docker-compose.dev.yml down inbucket", "dev:minio:start": "docker compose -f docker-compose.dev.yml up minio -d && docker compose -f docker-compose.dev.yml run minio-init", "dev:minio:stop": "docker compose -f docker-compose.dev.yml down minio", - "dev:cache:start": "docker compose -f docker-compose.dev.yml up cache -d", - "dev:cache:stop": "docker compose -f docker-compose.dev.yml down cache", "dev:setup": "pnpm install && docker compose -f docker-compose.dev.yml up -d && pnpm p:dev && pnpm --filter core migrate-dev && pnpm --filter core reset", "dev:teardown": "docker compose -f docker-compose.dev.yml down -v", "integration:setup": "docker compose -f docker-compose.test.yml --profile integration up -d", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0feafaf180..b5309116bf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -272,9 +272,6 @@ importers: '@faker-js/faker': specifier: ^9.0.0 version: 9.0.0 - '@fortedigital/nextjs-cache-handler': - specifier: ^1.2.0 - version: 1.2.0(next@15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(redis@4.7.0) '@googleapis/drive': specifier: ^8.16.0 version: 8.16.0 @@ -290,9 +287,6 @@ importers: '@icons-pack/react-simple-icons': specifier: ^10.2.0 version: 10.2.0(react@19.0.0) - '@neshca/cache-handler': - specifier: ^1.9.0 - version: 1.9.0(next@15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(redis@4.7.0) '@nimpl/getters': specifier: ^2.0.0 version: 2.0.0(next@15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -467,9 +461,6 @@ importers: reactflow: specifier: ^11.10.4 version: 11.11.4(@types/react@19.0.6)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) - redis: - specifier: ^4.7.0 - version: 4.7.0 rehype: specifier: ^13.0.2 version: 13.0.2 @@ -3102,12 +3093,6 @@ packages: '@formatjs/intl-localematcher@0.6.0': resolution: {integrity: sha512-4rB4g+3hESy1bHSBG3tDFaMY2CH67iT7yne1e+0CLTsGLDcmoEWWpJjjpWVaYgYfYuohIRuo0E+N536gd2ZHZA==} - '@fortedigital/nextjs-cache-handler@1.2.0': - resolution: {integrity: sha512-dHu7+D6yVHI5ii1/DgNSZM9wVPk8uKAB0zrRoNNbZq6hggpRRwAExV4J6bSGOd26RN6ZnfYaGLBmdb0gLpeBQg==} - peerDependencies: - next: '>=13.5.1' - redis: '>=4.6' - '@googleapis/drive@8.16.0': resolution: {integrity: sha512-Xi2mMrUTQ+gsfyouRGd0pfnL+jjg4n4sjKsJruM1y4DknuRfdSBTk5E//WrL0YJ/CqpcBgyd7L8DvaPRtxZD3Q==} engines: {node: '>=12.0.0'} @@ -3566,12 +3551,6 @@ packages: '@napi-rs/wasm-runtime@0.2.4': resolution: {integrity: sha512-9zESzOO5aDByvhIAsOy9TbpZ0Ur2AJbUI7UT73kcUTS2mxAMHOBaa1st/jAymNoCtvrit99kkzT1FZuXVcgfIQ==} - '@neshca/cache-handler@1.9.0': - resolution: {integrity: sha512-dh0x4pdjDKvPRfZF5DZb8TtOUkbBfeTodOUdQsHDuv0oiuqQ3p7GLx38f6bPn8Sa4he8HsWo+rM4S20ZRqr7pA==} - peerDependencies: - next: '>= 13.5.1 < 15' - redis: '>= 4.6' - '@next/env@15.0.4': resolution: {integrity: sha512-WNRvtgnRVDD4oM8gbUcRc27IAhaL4eXQ/2ovGbgLnPGUvdyDr8UdXP4Q/IBDdAdojnD2eScryIDirv0YUCjUVw==} @@ -5659,35 +5638,6 @@ packages: react: '>=17' react-dom: '>=17' - '@redis/bloom@1.2.0': - resolution: {integrity: sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==} - peerDependencies: - '@redis/client': ^1.0.0 - - '@redis/client@1.6.0': - resolution: {integrity: sha512-aR0uffYI700OEEH4gYnitAnv3vzVGXCFvYfdpu/CJKvk4pHfLPEy/JSZyrpQ+15WhXe1yJRXLtfQ84s4mEXnPg==} - engines: {node: '>=14'} - - '@redis/graph@1.1.1': - resolution: {integrity: sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==} - peerDependencies: - '@redis/client': ^1.0.0 - - '@redis/json@1.0.7': - resolution: {integrity: sha512-6UyXfjVaTBTJtKNG4/9Z8PSpKE6XgSyEb8iwaqDcy+uKrd/DGYHTWkUdnQDyzm727V7p21WUMhsqz5oy65kPcQ==} - peerDependencies: - '@redis/client': ^1.0.0 - - '@redis/search@1.2.0': - resolution: {integrity: sha512-tYoDBbtqOVigEDMAcTGsRlMycIIjwMCgD8eR2t0NANeQmgK/lvxNAvYyb6bZDD4frHRhIHkJu2TBRvB0ERkOmw==} - peerDependencies: - '@redis/client': ^1.0.0 - - '@redis/time-series@1.1.0': - resolution: {integrity: sha512-c1Q99M5ljsIuc4YdaCwfUEXsofakb9c8+Zse2qxTadu8TalLXuAESzLvFAvNVbkmSlvlzIQOLpBCmWI9wTOt+g==} - peerDependencies: - '@redis/client': ^1.0.0 - '@remirror/core-constants@3.0.0': resolution: {integrity: sha512-42aWfPrimMfDKDi4YegyS7x+/0tlzaqwPQCULLanv3DMIlu96KTJR0fM5isWX2UViOqlGnX6YFgqWepcX+XMNg==} @@ -5884,11 +5834,6 @@ packages: cpu: [x64] os: [linux] - '@rollup/rollup-linux-x64-gnu@4.40.1': - resolution: {integrity: sha512-XiK5z70PEFEFqcNj3/zRSz/qX4bp4QIraTy9QjwJAb/Z8GM7kVUsD0Uk8maIPeTyPCP03ChdI+VVmJriKYbRHQ==} - cpu: [x64] - os: [linux] - '@rollup/rollup-linux-x64-musl@4.21.2': resolution: {integrity: sha512-7twFizNXudESmC9oneLGIUmoHiiLppz/Xs5uJQ4ShvE6234K0VB1/aJYU3f/4g7PhssLGKBVCC37uRkkOi8wjg==} cpu: [x64] @@ -7974,10 +7919,6 @@ packages: resolution: {integrity: sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==} engines: {node: '>=6'} - cluster-key-slot@1.1.2: - resolution: {integrity: sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==} - engines: {node: '>=0.10.0'} - cmdk@1.0.4: resolution: {integrity: sha512-AnsjfHyHpQ/EFeAnG216WY7A5LiYCoZzCSygiLvfXC3H3LFGCprErteUcszaVluGOhuOTbJS3jWHrSDYPBBygg==} peerDependencies: @@ -9120,10 +9061,6 @@ packages: resolution: {integrity: sha512-Jh/AIwwgaxan+7ZUUmRLCjtchyDiqh4KjBJ5tW3plBZb5iL/BPcso8A5DlzeD9qlw0duCamnNdpFjxwaT0KyKg==} engines: {node: '>=14'} - generic-pool@3.9.0: - resolution: {integrity: sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==} - engines: {node: '>= 4'} - gensync@1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'} @@ -9975,6 +9912,7 @@ packages: resolution: {integrity: sha512-t0etAxTUk1w5MYdNOkZBZ8rvYYN5iL+2dHCCx/DpkFm/bW28M6y5nUS83D4XdZiHy35Fpaw6LBb+F88fHZnVCw==} engines: {node: '>=8.17.0'} hasBin: true + bundledDependencies: [] jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} @@ -10326,8 +10264,8 @@ packages: lru-cache@10.4.3: resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} - lru-cache@11.1.0: - resolution: {integrity: sha512-QIXZUBJUx+2zHUdQujWejBkcD9+cs94tLn0+YL8UrCh+D5sCXZ4c7LaEH48pNwRY3MLDgqUFyhlCyjJPf1WP0A==} + lru-cache@11.0.1: + resolution: {integrity: sha512-CgeuL5uom6j/ZVrg7G/+1IXqRY8JXX4Hghfy5YE0EhoYQWvndP1kufu58cmZLNIDKnRhZrXfdS9urVWx98AipQ==} engines: {node: 20 || >=22} lru-cache@5.1.1: @@ -11875,9 +11813,6 @@ packages: resolution: {integrity: sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==} engines: {node: '>=8'} - redis@4.7.0: - resolution: {integrity: sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==} - reflect.getprototypeof@1.0.10: resolution: {integrity: sha512-00o4I+DVrefhv+nX0ulyi3biSHCPDe+yLv5o/p6d/UVlirijB8E16FtfwSAi4g3tcqrQ4lRAqQSoFEZJehYEcw==} engines: {node: '>= 0.4'} @@ -13403,9 +13338,6 @@ packages: yallist@3.1.1: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} - yallist@4.0.0: - resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - yaml@1.10.2: resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==} engines: {node: '>= 6'} @@ -15543,16 +15475,6 @@ snapshots: dependencies: tslib: 2.8.1 - '@fortedigital/nextjs-cache-handler@1.2.0(next@15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(redis@4.7.0)': - dependencies: - '@neshca/cache-handler': 1.9.0(next@15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(redis@4.7.0) - cluster-key-slot: 1.1.2 - lru-cache: 11.1.0 - next: 15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) - redis: 4.7.0 - optionalDependencies: - '@rollup/rollup-linux-x64-gnu': 4.40.1 - '@googleapis/drive@8.16.0': dependencies: googleapis-common: 7.2.0 @@ -16142,13 +16064,6 @@ snapshots: '@tybys/wasm-util': 0.9.0 optional: true - '@neshca/cache-handler@1.9.0(next@15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(redis@4.7.0)': - dependencies: - cluster-key-slot: 1.1.2 - lru-cache: 10.4.3 - next: 15.2.3(@babel/core@7.25.2)(@opentelemetry/api@1.9.0)(@playwright/test@1.51.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) - redis: 4.7.0 - '@next/env@15.0.4': {} '@next/env@15.2.3': {} @@ -18625,32 +18540,6 @@ snapshots: - '@types/react' - immer - '@redis/bloom@1.2.0(@redis/client@1.6.0)': - dependencies: - '@redis/client': 1.6.0 - - '@redis/client@1.6.0': - dependencies: - cluster-key-slot: 1.1.2 - generic-pool: 3.9.0 - yallist: 4.0.0 - - '@redis/graph@1.1.1(@redis/client@1.6.0)': - dependencies: - '@redis/client': 1.6.0 - - '@redis/json@1.0.7(@redis/client@1.6.0)': - dependencies: - '@redis/client': 1.6.0 - - '@redis/search@1.2.0(@redis/client@1.6.0)': - dependencies: - '@redis/client': 1.6.0 - - '@redis/time-series@1.1.0(@redis/client@1.6.0)': - dependencies: - '@redis/client': 1.6.0 - '@remirror/core-constants@3.0.0': {} '@remirror/core-helpers@4.0.0': @@ -18819,9 +18708,6 @@ snapshots: '@rollup/rollup-linux-x64-gnu@4.35.0': optional: true - '@rollup/rollup-linux-x64-gnu@4.40.1': - optional: true - '@rollup/rollup-linux-x64-musl@4.21.2': optional: true @@ -21421,8 +21307,6 @@ snapshots: clsx@2.1.1: {} - cluster-key-slot@1.1.2: {} - cmdk@1.0.4(@types/react-dom@19.0.3(@types/react@19.0.6))(@types/react@19.0.6)(react-dom@19.0.0(react@19.0.0))(react@19.0.0): dependencies: '@radix-ui/react-dialog': 1.1.4(@types/react-dom@19.0.3(@types/react@19.0.6))(@types/react@19.0.6)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -22813,8 +22697,6 @@ snapshots: - encoding - supports-color - generic-pool@3.9.0: {} - gensync@1.0.0-beta.2: {} get-caller-file@2.0.5: {} @@ -24181,7 +24063,7 @@ snapshots: lru-cache@10.4.3: {} - lru-cache@11.1.0: {} + lru-cache@11.0.1: {} lru-cache@5.1.1: dependencies: @@ -25448,7 +25330,7 @@ snapshots: path-scurry@2.0.0: dependencies: - lru-cache: 11.1.0 + lru-cache: 11.0.1 minipass: 7.1.2 path-to-regexp@3.3.0: {} @@ -26269,15 +26151,6 @@ snapshots: indent-string: 4.0.0 strip-indent: 3.0.0 - redis@4.7.0: - dependencies: - '@redis/bloom': 1.2.0(@redis/client@1.6.0) - '@redis/client': 1.6.0 - '@redis/graph': 1.1.1(@redis/client@1.6.0) - '@redis/json': 1.0.7(@redis/client@1.6.0) - '@redis/search': 1.2.0(@redis/client@1.6.0) - '@redis/time-series': 1.1.0(@redis/client@1.6.0) - reflect.getprototypeof@1.0.10: dependencies: call-bind: 1.0.8 @@ -28208,8 +28081,6 @@ snapshots: yallist@3.1.1: {} - yallist@4.0.0: {} - yaml@1.10.2: {} yaml@2.3.1: {}