chore: remove Next.js Redis cache handler (#6725)

This commit is contained in:
Matti Nannt
2025-10-21 14:18:44 +02:00
committed by GitHub
parent f7f8f07778
commit c04c351244
4 changed files with 0 additions and 142 deletions

View File

@@ -1,99 +0,0 @@
// This cache handler follows the @fortedigital/nextjs-cache-handler example
// Read more at: https://github.com/fortedigital/nextjs-cache-handler
// @neshca/cache-handler dependencies
const { CacheHandler } = require("@neshca/cache-handler");
const createLruHandler = require("@neshca/cache-handler/local-lru").default;
// Next/Redis dependencies
const { createClient } = require("redis");
const { PHASE_PRODUCTION_BUILD } = require("next/constants");
// @fortedigital/nextjs-cache-handler dependencies
const createRedisHandler = require("@fortedigital/nextjs-cache-handler/redis-strings").default;
const createBufferStringHandler =
require("@fortedigital/nextjs-cache-handler/buffer-string-decorator").default;
const { Next15CacheHandler } = require("@fortedigital/nextjs-cache-handler/next-15-cache-handler");
// 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;
}
// If REDIS_URL is not set, we will use LRU cache only
if (!process.env.REDIS_URL) {
const lruCache = createLruHandler();
return { handlers: [lruCache] };
}
// Main promise initializing the handler
global.cacheHandlerConfigPromise = (async () => {
/** @type {import("redis").RedisClientType | null} */
let redisClient = null;
// eslint-disable-next-line turbo/no-undeclared-env-vars -- Next.js will inject this variable
if (PHASE_PRODUCTION_BUILD !== process.env.NEXT_PHASE) {
const settings = {
url: process.env.REDIS_URL, // Make sure you configure this variable
pingInterval: 10000,
};
try {
redisClient = createClient(settings);
redisClient.on("error", (e) => {
console.error("Redis error", e);
global.cacheHandlerConfig = null;
global.cacheHandlerConfigPromise = null;
});
} catch (error) {
console.error("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.error("Failed to connect Redis client:", error);
await redisClient
.disconnect()
.catch(() => console.error("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:",
});
global.cacheHandlerConfigPromise = null;
global.cacheHandlerConfig = {
handlers: [createBufferStringHandler(redisCacheHandler)],
};
return global.cacheHandlerConfig;
})();
return global.cacheHandlerConfigPromise;
});
module.exports = new Next15CacheHandler();

View File

@@ -16,8 +16,6 @@ const getHostname = (url) => {
const nextConfig = {
assetPrefix: process.env.ASSET_PREFIX_URL || undefined,
cacheHandler: require.resolve("./cache-handler.js"),
cacheMaxMemorySize: 0, // disable default in-memory caching
output: "standalone",
poweredByHeader: false,
productionBrowserSourceMaps: true,

View File

@@ -34,7 +34,6 @@
"@formbricks/surveys": "workspace:*",
"@formbricks/storage": "workspace:*",
"@formbricks/types": "workspace:*",
"@fortedigital/nextjs-cache-handler": "1.2.0",
"@hookform/resolvers": "5.0.1",
"@intercom/messenger-js-sdk": "0.0.14",
"@json2csv/node": "7.0.6",
@@ -98,7 +97,6 @@
"jsonwebtoken": "9.0.2",
"lexical": "0.36.2",
"lodash": "4.17.21",
"lru-cache": "11.1.0",
"lucide-react": "0.507.0",
"markdown-it": "14.1.0",
"mime-types": "3.0.1",
@@ -138,7 +136,6 @@
"devDependencies": {
"@formbricks/config-typescript": "workspace:*",
"@formbricks/eslint-config": "workspace:*",
"@neshca/cache-handler": "1.9.0",
"@testing-library/jest-dom": "6.6.3",
"@testing-library/react": "16.3.0",
"@tolgee/cli": "2.10.2",

38
pnpm-lock.yaml generated
View File

@@ -151,9 +151,6 @@ importers:
'@formbricks/types':
specifier: workspace:*
version: link:../../packages/types
'@fortedigital/nextjs-cache-handler':
specifier: 1.2.0
version: 1.2.0(next@15.5.2(@opentelemetry/api@1.9.0)(@playwright/test@1.52.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(redis@4.7.0)
'@hookform/resolvers':
specifier: 5.0.1
version: 5.0.1(react-hook-form@7.56.2(react@19.1.0))
@@ -343,9 +340,6 @@ importers:
lodash:
specifier: 4.17.21
version: 4.17.21
lru-cache:
specifier: 11.1.0
version: 11.1.0
lucide-react:
specifier: 0.507.0
version: 0.507.0(react@19.1.0)
@@ -458,9 +452,6 @@ importers:
'@formbricks/eslint-config':
specifier: workspace:*
version: link:../../packages/config-eslint
'@neshca/cache-handler':
specifier: 1.9.0
version: 1.9.0(next@15.5.2(@opentelemetry/api@1.9.0)(@playwright/test@1.52.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(redis@4.7.0)
'@testing-library/jest-dom':
specifier: 6.6.3
version: 6.6.3
@@ -1989,12 +1980,6 @@ packages:
'@formkit/auto-animate@0.8.2':
resolution: {integrity: sha512-SwPWfeRa5veb1hOIBMdzI+73te5puUBHmqqaF1Bu7FjvxlYSz/kJcZKSa9Cg60zL0uRNeJL2SbRxV6Jp6Q1nFQ==}
'@fortedigital/nextjs-cache-handler@1.2.0':
resolution: {integrity: sha512-dHu7+D6yVHI5ii1/DgNSZM9wVPk8uKAB0zrRoNNbZq6hggpRRwAExV4J6bSGOd26RN6ZnfYaGLBmdb0gLpeBQg==}
peerDependencies:
next: '>=13.5.1'
redis: '>=4.6'
'@gar/promisify@1.1.3':
resolution: {integrity: sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==}
@@ -2446,12 +2431,6 @@ packages:
'@neoconfetti/react@1.0.0':
resolution: {integrity: sha512-klcSooChXXOzIm+SE5IISIAn3bYzYfPjbX7D7HoqZL84oAfgREeSg5vSIaSFH+DaGzzvImTyWe1OyrJ67vik4A==}
'@neshca/cache-handler@1.9.0':
resolution: {integrity: sha512-dh0x4pdjDKvPRfZF5DZb8TtOUkbBfeTodOUdQsHDuv0oiuqQ3p7GLx38f6bPn8Sa4he8HsWo+rM4S20ZRqr7pA==}
peerDependencies:
next: '>= 13.5.1 < 15'
redis: '>= 4.6'
'@next/env@15.5.2':
resolution: {integrity: sha512-Qe06ew4zt12LeO6N7j8/nULSOe3fMXE4dM6xgpBQNvdzyK1sv5y4oAP3bq4LamrvGCZtmRYnW8URFCeX5nFgGg==}
@@ -12475,16 +12454,6 @@ snapshots:
'@formkit/auto-animate@0.8.2': {}
'@fortedigital/nextjs-cache-handler@1.2.0(next@15.5.2(@opentelemetry/api@1.9.0)(@playwright/test@1.52.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(redis@4.7.0)':
dependencies:
'@neshca/cache-handler': 1.9.0(next@15.5.2(@opentelemetry/api@1.9.0)(@playwright/test@1.52.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(redis@4.7.0)
cluster-key-slot: 1.1.2
lru-cache: 11.1.0
next: 15.5.2(@opentelemetry/api@1.9.0)(@playwright/test@1.52.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
redis: 4.7.0
optionalDependencies:
'@rollup/rollup-linux-x64-gnu': 4.46.1
'@gar/promisify@1.1.3':
optional: true
@@ -13014,13 +12983,6 @@ snapshots:
'@neoconfetti/react@1.0.0': {}
'@neshca/cache-handler@1.9.0(next@15.5.2(@opentelemetry/api@1.9.0)(@playwright/test@1.52.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(redis@4.7.0)':
dependencies:
cluster-key-slot: 1.1.2
lru-cache: 10.4.3
next: 15.5.2(@opentelemetry/api@1.9.0)(@playwright/test@1.52.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
redis: 4.7.0
'@next/env@15.5.2': {}
'@next/eslint-plugin-next@15.3.2':