next-shared-cache icon indicating copy to clipboard operation
next-shared-cache copied to clipboard

[almost done] Next.js 15 support

Open better-salmon opened this issue 10 months ago β€’ 16 comments

Summary by CodeRabbit

  • New Features

    • Added a Redis-based cache handler with pub/sub tag expiration support and a new cache handler that performs no operations.
    • Introduced advanced cache handler utilities for remote stores and improved cache management options.
    • Implemented new helper utilities for tag and age estimation handling.
  • Bug Fixes

    • Improved error handling and type safety in cache handlers.
    • Enhanced timeout management for Redis operations.
    • Fixed and clarified return types across multiple components and functions.
  • Refactor

    • Streamlined and modernized module imports/exports to ES module syntax.
    • Simplified and unified cache handler APIs, removing deprecated and redundant files.
    • Consolidated and improved cache handler logic, including removal of legacy caching strategies.
  • Chores

    • Upgraded dependencies and development tooling across the project.
    • Updated TypeScript, ESLint, and Prettier configurations for stricter checks and consistency.
    • Removed deprecated packages, configuration files, and documentation for obsolete modules.
  • Tests

    • Added comprehensive tests for new utilities and removed outdated test suites.
  • Style

    • Standardized code formatting and updated editor/formatter settings.
  • Documentation

    • Updated and removed documentation to reflect the new cache handler architecture and utilities.

better-salmon avatar Feb 09 '25 15:02 better-salmon

⚠️ No Changeset found

Latest commit: 9fdb6a4480b156d7377e35e2e0574f5ad93daa37

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

πŸ’₯ An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package "@neshca/cache-handler" depends on the ignored package "@repo/eslint-config", but "@neshca/cache-handler" is not being ignored. Please add "@neshca/cache-handler" to the `ignore` option.

changeset-bot[bot] avatar Feb 09 '25 15:02 changeset-bot[bot]

Walkthrough

This set of changes restructures the codebase by removing deprecated or redundant packages, files, and configurations, especially those related to classic cache handling and server modules. The cache handler logic is refactored for improved type safety, modularity, and ES module compatibility. New utilities and configurations are introduced for TypeScript, ESLint, and Vitest. Redis and LRU cache handlers are modernized, and tests are updated or replaced. Several documentation and configuration files are updated or deleted to align with the new project structure.

Changes

File(s) / Path(s) Change Summary
.gitignore, .prettierignore, .vscode/settings.json, .vscode/extensions.json Updated ignore lists, switched default formatter to Prettier, removed Biome settings, added TypeScript SDK path.
.github/workflows/tests.yml, .github/workflows/test-docs.yml, .github/dependabot.yml Updated workflow paths, removed biome references, broadened lru-cache version constraint.
.changeset/config.json Removed @neshca/server from ignore list.
package.json, turbo.json, pnpm-workspace.yaml Updated scripts, dependencies, renamed lint tasks, added type check tasks, updated Turbo config, and workspace dependency build settings.
internal/typescript-config/* Added new TypeScript configs for Node 20, Node 22, Next.js, and testing; updated strictness and module settings.
internal/eslint-config/* Added new base, lib, and Vitest ESLint configs; updated exports and dependencies in package.json; refactored Next.js ESLint config for improved modularity.
docs/cache-handler-docs/* Updated dependencies, scripts, and imports; removed TypeScript error suppression comment.
apps/cache-testing/package.json, apps/cache-testing/tsconfig.json, apps/cache-testing/next.config.ts Enabled ES modules, updated dependencies, scripts, and Next.js config; removed strict null checks and plugins from tsconfig.
apps/cache-testing/cache-handler-*.js, apps/cache-testing/redis.js, apps/cache-testing/cache-handler-none.js Migrated to ES module syntax, updated import paths for handlers, added new Redis and "none" cache handler examples.
apps/cache-testing/create-instances.sh, apps/cache-testing/create-instances.ts Replaced Bash setup script with a TypeScript version for managing test instances.
apps/cache-testing/cluster.config.js Migrated to ES module export.
apps/cache-testing/src/app/*, apps/cache-testing/src/pages/*, apps/cache-testing/src/components/*, apps/cache-testing/src/utils/* Updated function and return types to use React.ReactNode, improved async parameter handling, removed deprecated cache strategies, and cleaned up imports.
apps/cache-testing/src/globals.css Changed font-family quotes from double to single.
apps/cache-testing/tests/app.spec.ts, apps/cache-testing/tests/pages.spec.ts Removed tests for unstable and classic cache, updated test logic for revalidation.
packages/cache-handler/package.json, packages/cache-handler/.npmignore, packages/cache-handler/tsconfig.json, packages/cache-handler/tsconfig.build.json, packages/cache-handler/vitest.config.ts, packages/cache-handler/eslint.config.js Refactored exports, scripts, dependencies; switched to TypeScript/Vitest; added ESLint config; updated TypeScript settings and build config.
packages/cache-handler/src/cache-handler.ts, packages/cache-handler/src/constants.ts, packages/cache-handler/src/next-common-types.ts Refactored for stricter type safety, explicit enums, and improved expiration logic; added new constant.
packages/cache-handler/src/handlers/* Refactored Redis and LRU handlers for consistent timeout handling, type safety, and modular imports; updated serialization to use superjson; improved key grouping and slot handling in Redis cluster.
packages/cache-handler/src/helpers/* Removed deprecated helpers, replaced with new isTagImplicit and getTagsFromHeaders utilities, consolidated exports.
packages/cache-handler/src/functions/* Removed classic and unstable cache exports and implementations.
packages/cache-handler/src/instrumentation/* Refactored initial cache registration, removed route/fetch cache logic, updated imports and types.
packages/cache-handler/src/use-cache-cache.ts, packages/cache-handler/src/use-cache/node-redis.ts Added new cache handler and Redis store implementations for modular, tag-based caching with pub/sub expiration.
packages/cache-handler/src/utils/* Added new age estimation and header tag extraction utilities; removed deprecated helpers.
packages/cache-handler/test/utils/compose-age-estimation-fn.test.ts Added comprehensive tests for age estimation utility.
internal/next-common/package.json, internal/next-common/tsconfig.json, internal/next-lru-cache/package.json, internal/next-lru-cache/tsconfig.json, packages/json-replacer-reviver/*, packages/server/*, packages/cache-handler/tsup.config.ts, packages/cache-handler/src/helpers/create-validated-age-estimation-function.test.ts, packages/cache-handler/src/helpers/create-validated-age-estimation-function.ts, packages/cache-handler/src/helpers/promise-with-timeout.test.ts, packages/cache-handler/src/helpers/promise-with-timeout.ts, packages/cache-handler/src/helpers/is-implicit-tag.ts, packages/cache-handler/src/helpers/is-tags-manifest.ts, packages/cache-handler/src/helpers/get-tags-from-headers.ts, packages/cache-handler/src/helpers/get-timeout-redis-command-options.ts, packages/cache-handler/src/functions/nesh-cache.ts, packages/cache-handler/src/functions/nesh-classic-cache.ts, packages/cache-handler/src/handlers/server.ts, packages/cache-handler/src/instrumentation/instrumentation.ts, apps/cache-testing/src/app/app/with-params/nesh-cache/[slug]/page.tsx, apps/cache-testing/src/app/app/with-params/unstable-cache/[slug]/page.tsx, apps/cache-testing/src/pages/api/pages-cached-api.ts, apps/cache-testing/src/pages/pages/no-paths/ssr-with-cache/200.tsx, apps/cache-testing/src/utils/create-pages-get-get-server-side-props-cached.ts, biome.json, packages/json-replacer-reviver/tsup.config.ts, packages/server/tsup.config.ts, packages/server/.npmignore, packages/json-replacer-reviver/.npmignore, packages/json-replacer-reviver/CHANGELOG.md, packages/server/CHANGELOG.md, packages/json-replacer-reviver/LICENSE, packages/server/LICENSE, packages/json-replacer-reviver/README.md, packages/server/README.md Deleted deprecated, redundant, or replaced files, including classic cache, server, and helper modules, as well as documentation and configuration files.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant CacheHandler
    participant LRUHandler
    participant RedisHandler
    participant RemoteStore
    participant RedisClient

    App->>CacheHandler: get(key, ctx)
    CacheHandler->>LRUHandler: get(key, {implicitTags})
    LRUHandler-->>CacheHandler: value/null
    CacheHandler->>RedisHandler: get(key, {implicitTags})
    RedisHandler-->>CacheHandler: value/null
    CacheHandler-->>App: value/null

    App->>CacheHandler: set(key, value, ctx)
    CacheHandler->>LRUHandler: set(key, value)
    LRUHandler-->>CacheHandler: ack
    CacheHandler->>RedisHandler: set(key, value)
    RedisHandler-->>CacheHandler: ack
    CacheHandler-->>App: ack

    App->>CacheHandler: revalidateTag(tag)
    CacheHandler->>LRUHandler: revalidateTag(tag)
    LRUHandler-->>CacheHandler: ack
    CacheHandler->>RedisHandler: revalidateTag(tag)
    RedisHandler-->>CacheHandler: ack
    CacheHandler-->>App: ack

    App->>RemoteStore: get(cacheKey)
    RemoteStore->>RedisClient: get(key) with timeout
    RedisClient-->>RemoteStore: value/null
    RemoteStore-->>App: value/null

    App->>RemoteStore: set(cacheKey, entry)
    RemoteStore->>RedisClient: set(key, value) with timeout
    RedisClient-->>RemoteStore: ack
    RemoteStore-->>App: ack

    App->>RemoteStore: expireTags(tags)
    RemoteStore->>RedisClient: publish expired tags
    RedisClient-->>RemoteStore: ack
    RemoteStore-->>App: ack

[!NOTE]

⚑️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Learn more here.


[!NOTE]

⚑️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings. Enjoy the performance boostβ€”your workflow just got faster.

✨ Finishing Touches
  • [ ] πŸ“ Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Feb 09 '25 15:02 coderabbitai[bot]

@better-salmon do we have any timeline for when this will be merged? I'm currently using a fork and it has some issues.

AkshatKejriwal avatar Mar 24 '25 18:03 AkshatKejriwal

#1027 has this been already considered?

AyronK avatar Mar 27 '25 11:03 AyronK

@better-salmon, I'd be willing to take on the remaining of this PR and contribute would just like to align on what the remaining work is before I dive deep

Pruxis avatar Apr 18 '25 09:04 Pruxis

let's make sure to show a little bit of appreciation for the great work Arseny has done so far 😊

https://opencollective.com/caching-tools#category-CONTRIBUTE

@Pruxis @ricotijsen @Rikard-Johansson97 @iz-podpolja @ishida0210 @Edge1S-mgawlik @druckmax @MrBuBBLs @QurcoJr @Andr1yk

jobenjada avatar May 08 '25 12:05 jobenjada

@jobenjada Thank you for sharing this 😁 I completely agree - Arseny has done incredible work with the caching tools project. It's always important to show appreciation for developers who contribute so much to the open source community. I just made a small donation to support the project. Though it's not much, I wanted to contribute something to show my appreciation for Arseny's hard work and dedication. Every bit helps sustain these valuable open source efforts!

ishida0210 avatar May 10 '25 04:05 ishida0210

Very nice work, if there are some more things where we can help with development/test, let's make it happen :)

royvou avatar May 12 '25 17:05 royvou

Would love to see this cross the line soon! We're looking to use redis clusters in a self hosted Next.js setup, and this would make the approach much easier than writing a custom solution. πŸš€

blairmcalpine avatar May 22 '25 20:05 blairmcalpine

Would love to see this cross the line soon! We're looking to use redis clusters in a self hosted Next.js setup, and this would make the approach much easier than writing a custom solution. πŸš€

We are welcoming anybody to try out: https://github.com/trieb-work/nextjs-turbo-redis-cache While waiting for this PR to be done.

We saw around 80% less redis traffic with our approach and because in the long run also 90% less memory usage in Redis in comparison to our setup with neshca.

JannikZed avatar May 30 '25 08:05 JannikZed

We are welcoming anybody to try out: https://github.com/trieb-work/nextjs-turbo-redis-cache

@JannikZed would love to but unfortunately cannot due to

It is not compatible if you are using Pages Router

We are moving to app router but currently are in a hybrid state split across app and pages. We can't easily move off pages router without a shared cache, hence waiting for this to land.

Is this something you plan to support?

harry-gocity avatar May 30 '25 12:05 harry-gocity

For people needing a fast switch with minimal breaking changes -> https://github.com/fortedigital/nextjs-cache-handler

AyronK avatar May 31 '25 20:05 AyronK

@better-salmon Is there anything that can be done from the community here to get this moving?

I've been telling engineers at my work that this is coming soon - almost done - for several months now. I don't see a migration path to a community replacement (https://github.com/fortedigital/nextjs-cache-handler, https://github.com/trieb-work/nextjs-turbo-redis-cache) that supports pages router, so feel rather stuck.

If there are any outstanding tasks, that could help get this released, it would be great to align the community so those who want to could try and contribute πŸ™πŸ»

harry-gocity avatar Jul 30 '25 12:07 harry-gocity

@harry-gocity fyi even though most users who decided to go with https://github.com/fortedigital/nextjs-cache-handler use app router, the library has recently had compatibility fixes for Next 15 with pages router as well.

AyronK avatar Jul 30 '25 16:07 AyronK

Well, Next 16 is around the corner - this package seems pretty much dead.

AyronK avatar Oct 15 '25 11:10 AyronK

Well, Next 16 is around the corner - this package seems pretty much dead.

@AyronK I've been using your alternative in production for a week already with good results. Thanks for it!

fbudassi avatar Oct 15 '25 13:10 fbudassi