/** * Redis-based Data Cache Handler for "use cache" directive * For production use with distributed Next.js deployments * * This handler stores cache entries in Redis, allowing multiple * Next.js instances to share the same cache. */ import type { DataCacheHandler } from "./types.js"; export interface RedisDataCacheHandlerOptions { /** * Redis client instance (ioredis compatible) */ redis: RedisClient; /** * Key prefix for all cache entries * @default "nextjs:data-cache:" */ keyPrefix?: string; /** * Key prefix for tag manifest * @default "nextjs:tags:" */ tagPrefix?: string; /** * Enable debug logging * @default false */ debug?: boolean; /** * Default TTL for cache entries in seconds * Used if entry doesn't specify expiration * @default 86400 (24 hours) */ defaultTTL?: number; } /** * Redis client interface (ioredis compatible) * Uses ioredis-style SET with "EX" positional args: set(key, value, "EX", seconds) */ export interface RedisClient { get(key: string): Promise; set(key: string, value: string, ...args: unknown[]): Promise; del(...keys: string[]): Promise; exists(...keys: string[]): Promise; ttl(key: string): Promise; hGet(key: string, field: string): Promise; hSet(key: string, field: string, value: string): Promise; hGetAll(key: string): Promise>; } /** * Create a Redis-based data cache handler for "use cache" directive * * @example * ```typescript * // redis-cache-handler.mjs * import { createClient } from 'redis'; * import { createRedisDataCacheHandler } from '@mrjasonroy/better-nextjs-cache-handler/data-cache'; * * const redis = createClient({ * url: process.env.REDIS_URL * }); * * await redis.connect(); * * export default createRedisDataCacheHandler({ * redis, * keyPrefix: 'myapp:cache:', * debug: process.env.NODE_ENV === 'development' * }); * ``` * * Then in next.config.js: * ```javascript * module.exports = { * cacheComponents: true, * cacheHandlers: { * default: require.resolve('./redis-cache-handler.mjs'), * remote: require.resolve('./redis-cache-handler.mjs') // Same handler for remote * } * } * ``` */ export declare function createRedisDataCacheHandler(options: RedisDataCacheHandlerOptions): DataCacheHandler; //# sourceMappingURL=redis.d.ts.map