-
Notifications
You must be signed in to change notification settings - Fork 30k
docs: cacheHandlers use object instead of class #86022
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
docs: cacheHandlers use object instead of class #86022
Conversation
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
| module.exports = { | ||
| constructor() { | ||
| this.client = createClient({ url: process.env.REDIS_URL }) | ||
| this.client.connect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The object literal syntax doesn't support constructor methods like classes do. When converting from a class to an object, the Redis client initialization needs to be moved outside the exported object. Consider restructuring like this:
const { createClient } = require('redis')
const client = createClient({ url: process.env.REDIS_URL })
client.connect()
module.exports = {
// Methods that use client
async get(cacheKey, softTags) {
// Implementation using client
},
// Other methods...
}This ensures the Redis client is properly initialized before the module is exported and can be used by the handler methods.
| module.exports = { | |
| constructor() { | |
| this.client = createClient({ url: process.env.REDIS_URL }) | |
| this.client.connect() | |
| const { createClient } = require('redis') | |
| const client = createClient({ url: process.env.REDIS_URL }) | |
| client.connect() | |
| module.exports = { | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
docs/01-app/03-api-reference/05-config/01-next-config-js/cacheHandlers.mdx
Outdated
Show resolved
Hide resolved
icyJoseph
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, and come to think I actually answered an issue about this with the right info... 🤦 it happens
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> This PR fixes the docs' example where it used class (like cacheHandler (no s)), but cacheHandlers expect an object. --------- Co-authored-by: Joseph <[email protected]>
This PR fixes the docs' example where it used class (like cacheHandler (no s)), but cacheHandlers expect an object.