Skip to content

fix(cache): log "caches is not defined" only once#4871

Open
yuintei wants to merge 1 commit intohonojs:mainfrom
yuintei:fix/cache-deduplicate-log
Open

fix(cache): log "caches is not defined" only once#4871
yuintei wants to merge 1 commit intohonojs:mainfrom
yuintei:fix/cache-deduplicate-log

Conversation

@yuintei
Copy link
Copy Markdown
Contributor

@yuintei yuintei commented Apr 11, 2026

The log is repeated for every cache() call when globalThis.caches is not available. This PR ensures the message is logged only once.

$ vite

  VITE v8.0.0  ready in 675 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
Cache Middleware is not enabled because caches is not defined.
Cache Middleware is not enabled because caches is not defined.
Cache Middleware is not enabled because caches is not defined.
Cache Middleware is not enabled because caches is not defined.
Cache Middleware is not enabled because caches is not defined.
Cache Middleware is not enabled because caches is not defined.
Cache Middleware is not enabled because caches is not defined.
Cache Middleware is not enabled because caches is not defined.
(repeats...)
Using vars defined in .env

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code (N/A)

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.89%. Comparing base (1aa32fb) to head (66b2c61).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4871   +/-   ##
=======================================
  Coverage   92.89%   92.89%           
=======================================
  Files         177      177           
  Lines       11797    11801    +4     
  Branches     3515     3514    -1     
=======================================
+ Hits        10959    10963    +4     
  Misses        837      837           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe
Copy link
Copy Markdown
Member

Hi @yuintei

This PR is not bad. BUT, the cache function is called only once in the initialization phase, so usually the log shows only one. So, in your environment, showing the log multiple times may be a little weird. Can you share the minimal project to reproduce it?

yuintei added a commit to yuintei/hono-cache-log-repro that referenced this pull request Apr 12, 2026
@yuintei
Copy link
Copy Markdown
Contributor Author

yuintei commented Apr 12, 2026

Hi @yusukebe, thanks for the review. Here's a minimal reproduction: Link

I use cache() on 20+ routes, so the log fills up the terminal on every dev server start, which is why I made this PR.

@yusukebe
Copy link
Copy Markdown
Member

@yuintei

Thank you for the response and repro! I considered that declaring the variable with let and using it like globally is not a good design. I have another idea and will implement it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants