cachegoose icon indicating copy to clipboard operation
cachegoose copied to clipboard

Could this work with multiple mongoose instances

Open ziggy6792 opened this issue 4 years ago • 0 comments

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.

ziggy6792 avatar Oct 05 '21 07:10 ziggy6792