Replies: 2 comments 2 replies
-
You can create your class in a file and export the instance, that should give you the singleton. Note that, in development, Remix is clearing the require cache on each request and requiring the built code again so you don't need to restart the server on every file change, this will make your singleton be instantiated again, in development, one way to prevent this is to store the instance in In production it should work correctly as far as you keep the process running, this means if you use Serverless platforms like Vercel or Netlify or Cloudflare it will be impossible to avoid this. You need to use a deployment platform where you have the process running all the time. |
Beta Was this translation helpful? Give feedback.
-
Hi @sergiodxa My site is on Vercel and the singleton are initialized on each visit. I want to push my posts data to algolia on server started. I wrote it in But is there any way that I can run specific job on |
Beta Was this translation helpful? Give feedback.
-
Trying to understand what is the suggested pattern for singleton (per Server process); to be used for connections that are considered heavyweight.
Let's say I have a scenario in the root level where it uses the loader to create a connection for Temporal Client to be used through the rest of this app; but it does not seem to behave as expected.
At root:
When used in a route; let's say About page:
The Output shows the connection is instantiated again.
The singleton setup just uses the basic pattern;
Any guidance/advice or how to ensure the initialized instance is the one to be used instead of recreating?
Beta Was this translation helpful? Give feedback.
All reactions