prisma-redis-middleware icon indicating copy to clipboard operation
prisma-redis-middleware copied to clipboard

Cache based on model not over-riding default

Open pkellner opened this issue 2 years ago • 0 comments

Sorry for posting as a bug as I'm sure it's a misunderstanding.

I've got middleware like below.

What's odd is that I can see in RedisInsights that the model "Attendees" cache gets set to the defaultCacheTime and not the attendeesCacheTime as I would expect.

If I leave out cacheTime: defaultCacheTime then I get cache load errors. Not exactly understanding that.

const defaultCacheTime = 60 * 15; // 60 * 15 = 15 minutes

const attendeesCacheTime = 3600 * 24 * 1;  // 3600 * 24 * 1 = 1 days

const cacheMiddleware = createPrismaRedisCache({
  models: [{ model: "Attendees", cacheTime: attendeesCacheTime }],
  excludeModels: ["MeetupCodeCampYear"],
  storage: {
    type: "redis",
    options: { client: redis, invalidation: { referencesTTL: defaultCacheTime } },
  },
  cacheTime: defaultCacheTime,

  onHit: (key: string) =>
    process.env.NODE_ENV !== "production" &&
    process.env.SHOW_CACHE_HITS === "true"
      ? console.log("Hit: ✅  \n", key)
      : null,

  onMiss: (key: string) =>
    process.env.NODE_ENV !== "production" &&
    process.env.SHOW_CACHE_MISSES === "true"
      ? console.log("Miss: ❌  \n", key)
      : null,
});

pkellner avatar Sep 03 '23 15:09 pkellner