Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Cache based on model not over-riding default #592

Open
pkellner opened this issue Sep 3, 2023 · 0 comments
Open

Cache based on model not over-riding default #592

pkellner opened this issue Sep 3, 2023 · 0 comments

Comments

@pkellner
Copy link

pkellner commented Sep 3, 2023

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,
});
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants