Skip to content
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

Could this work with multiple mongoose instances #72

Open
ziggy6792 opened this issue Oct 5, 2021 · 0 comments
Open

Could this work with multiple mongoose instances #72

ziggy6792 opened this issue Oct 5, 2021 · 0 comments

Comments

@ziggy6792
Copy link

Is it possible to create multiple mongoose.Mongoose instances and each of them to have their own cache.

My Setup

type-graphql backend with typegoose/mongoose
Code here

My Question

I am trying to have each GraphQL request create a separate mongoose instance with its own cache like this

export const getMongooseInstance = async (): Promise<Mongoose> => {
  const mongooseInstance = await connect(MONGO_DB_URL);
  cachegoose(mongooseInstance);
  return mongooseInstance;
};

See here

The idea is that I can pass my instance into getModelForClass like this

getModelForClass(clazz, { existingMongoose: this.mongooseInstance })

See here.

So that the models for each request will use a separate mongooseInstance with a separate cache. I want this so that when a request requests the same data twice the cache is used.

However with my current implementation the cache seems to be global across the created mongoose instances.

Is this behaviour possible and if not how could I extend cachegoose to add this functionality.

Thanks.

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

No branches or pull requests

1 participant