Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dynamicIO] cacheHandlers are not used in production #72552

Open
apostolos opened this issue Nov 10, 2024 · 4 comments
Open

[dynamicIO] cacheHandlers are not used in production #72552

apostolos opened this issue Nov 10, 2024 · 4 comments
Labels
bug Issue was opened via the bug report template. dynamicIO Related to dynamicIO.

Comments

@apostolos
Copy link
Contributor

Link to the code that reproduces this issue

https://github.com/apostolos/next-custom-cache-handlers

To Reproduce

  1. Start the application in development pnpm run dev
  2. Open the root page https://localhost:3000
  3. You should see customHandlers code being called ([DEBUG] lines in stdout)
  4. Stop & build the app pnpm run build. You'll notice that customHandlers code is correctly called during build.
  5. Run the app pnpm run start
  6. Repeat step 2. You'll notice that customHandlers code is no longer being called.

Current vs. Expected behavior

Being able to use custom cache handlers in production is critical for self-hosting.

Following Next.js 15's recommendations, we migrated our app to "use cache" and implemented a custom shared cache handler (Redis-backed) in order to deploy the app in multiple instances. However, the custom cache handlers seem to be completely ignored in production builds.

During development our custom cache handler works fine:

> next dev

   ▲ Next.js 15.0.4-canary.4
   - Local:        http://localhost:3000
   - Environments: .env
   - Experiments (use with caution):
     · dynamicIO
     · cacheHandlers

 ✓ Starting...
 ✓ Ready in 1158ms
using filesystem cache handler
not using memory store for fetch cache
 ○ Compiling / ...
 ✓ Compiled / in 1038ms (555 modules)
[DEBUG] CustomCacheHandler::Get ["development","808c376d246055d9af478f3399d551bf45701b001f",[]] [ '_N_T_/layout', '_N_T_/page', '_N_T_/' ]
[DEBUG] CustomCacheHandler::Set ["development","808c376d246055d9af478f3399d551bf45701b001f",[]]
[DEBUG] CustomCacheHandler::Get ["development","808c376d246055d9af478f3399d551bf45701b001f",[]] []
revalidateTag []
[DEBUG] CustomCacheHandler::Get ["development","808c376d246055d9af478f3399d551bf45701b001f",[]] []
 GET / 200 in 1201ms

During builds, it also seems to be working as expected:

> next build

   ▲ Next.js 15.0.4-canary.4
   - Environments: .env
   - Experiments (use with caution):
     · dynamicIO
     · cacheHandlers

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types
   Collecting page data  .using filesystem cache handler
not using memory store for fetch cache
using filesystem cache handler
not using memory store for fetch cache
 ✓ Collecting page data
using filesystem cache handler
not using memory store for fetch cache
[DEBUG] CustomCacheHandler::Get ["8mvY93v1cZgxPTBtesVSp","808c376d246055d9af478f3399d551bf45701b001f",[]] [ '_N_T_/layout', '_N_T_/page', '_N_T_/' ]
[DEBUG] CustomCacheHandler::Set ["8mvY93v1cZgxPTBtesVSp","808c376d246055d9af478f3399d551bf45701b001f",[]]
 ✓ Generating static pages (4/4)
 ✓ Collecting build traces
 ✓ Finalizing page optimization

Route (app)                              Size     First Load JS
┌ ƒ /                                    140 B           100 kB
└ ○ /_not-found                          896 B           101 kB
+ First Load JS shared by all            100 kB
  ├ chunks/0c1cf05f-2460cb4528b4f89a.js  52.5 kB
  ├ chunks/851-fb97669a7797ba52.js       45.6 kB
  └ other shared chunks (total)          1.86 kB


○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand

However, when we launch the app our custom cache handler is never used.

> next start

   ▲ Next.js 15.0.4-canary.4
   - Local:        http://localhost:3000

 ✓ Starting...
 ✓ Ready in 163ms
using filesystem cache handler
not using memory store for fetch cache

Although it is initialized (the module is getting loaded), the get(), set() functions are never called. It looks like the configuration is ignored and it falls back to using the default memory cache.

This is a major deal breaker since we cannot self-host any serious app without control of the caching. Our workaround is to revert back to using next: {revalidate, tags}/unstable_cache() instead of "use cache"/cacheLife()/cacheTags().

Provide environment information

Node.js v23.1.0

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 23.1.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.12.3
Relevant Packages:
  next: 15.0.4-canary.4 // Latest available version is detected (15.0.4-canary.4).
  eslint-config-next: N/A
  react: 19.0.0-rc-66855b96-20241106
  react-dom: 19.0.0-rc-66855b96-20241106
  typescript: 5.6.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

dynamicIO

Which stage(s) are affected? (Select all that apply)

next start (local)

Additional context

Self-hosted

@apostolos apostolos added the bug Issue was opened via the bug report template. label Nov 10, 2024
@github-actions github-actions bot added the dynamicIO Related to dynamicIO. label Nov 10, 2024
@snraets
Copy link

snraets commented Nov 11, 2024

I am having enormous problems adding Redis to caching

@mikebywaters
Copy link

We're still encountering this issue in 15.0.4-canary.31

@snraets
Copy link

snraets commented Dec 3, 2024 via email

@Reza-tm

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. dynamicIO Related to dynamicIO.
Projects
None yet
Development

No branches or pull requests

4 participants