Skip to content

Is it possible to prepopulate the cache with initial data on startup using instrumentation.ts? #50

@tamadam

Description

@tamadam

Hi,

We’re running in a multi-stage environment (dev/test/prod), all using the same Docker image.

With @neshca/cache-handler, we previously handled cache prepopulation by having generateStaticParams return an empty array during build, and then using the instrumentation.ts file to prepopulate the Redis cache at startup.
This is how our generateStaticParams looked like previously:

export async function generateStaticParams() {
  if (isDuringProductionBuild()) return []

  return SUPPORTED_LANGUAGES.map(lang => ({ lang }))
}

And our instrumentation.ts

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    const { registerInitialCache } = await import('@neshca/cache-handler/instrumentation')
    const CacheHandler = (await import('./cache-handler.mjs')).default
    console.info('Loading the initial cache')
    await registerInitialCache(CacheHandler, { fetch: true, pages: true, routes: true })
    console.info('Loaded the initial cache')
  }
}

Is it possible to achieve something similar with nextjs-turbo-redis-cache?
If so, could you provide some guidance or an example of how to set that up?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions