Skip to content

Is there a way to include build id in cache key? #158

Closed Answered by better-salmon
samueldusek asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @samueldusek, thank you for your interest in my project. There are two ways to achieve your goals. You can use both with custom Handlers, but I will only show createHandler in this example for simplicity.

1. Use env variables

According to the generateBuildId docs, you can use env variables to generate a buildId. It is the recommended way to do it.

In your next.config.js:

module.exports = {
  generateBuildId: async () => {
    // This could be anything, using the latest git hash
    return process.env.GIT_HASH;
  },
};

Then, in your cache-handler.js:

IncrementalCache.onCreation(
  createHandler({
    client,
    keyPrefix: process.env.GIT_HASH,
  })
);

If this isn't feasible for you, …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@samueldusek
Comment options

Answer selected by samueldusek
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants