Coder Social home page Coder Social logo

Comments (4)

Asjas avatar Asjas commented on May 18, 2024 3

v2.0.0 has been released.

from prisma-redis-middleware.

Asjas avatar Asjas commented on May 18, 2024 1

I know most Prisma actions (queries and mutations) usually include an id field in the args or next return value.

I don't know if this is true for all actions or all databases that are supported by Prisma, but that could be something that would allow me to create a more refined cache where only cached queries that match a model AND that match an id field can be deleted.

I'm curious what other people's opinion on this would be?

from prisma-redis-middleware.

f-o-w-l avatar f-o-w-l commented on May 18, 2024 1

I know most Prisma actions (queries and mutations) usually include an id field in the args or next return value.

I don't know if this is true for all actions or all databases that are supported by Prisma, but that could be something that would allow me to create a more refined cache where only cached queries that match a model AND that match an id field can be deleted.

I'm curious what other people's opinion on this would be?

It makes sense for me to call it a primary key for each model. Models are basically tables, right? If so, then there should only be one primary key per model. Disclaimer, I haven't used Prisma, I'm currently learning it. Referencing #62, I think it would be great to have this kind of API:

prismaClient.$use(
  createPrismaRedisCache({
    models: [
      {
        model: "User",
        primaryKey: "id",
      },
      {
        model: "Post",
        cacheTime: 900,
        primaryKey: "postId",
        excludeCacheMethods: ["findMany", "aggregate"],
      }
    ],
    defaultCacheTime: 300,
    redis,
    defaultExcludeCacheMethods: ["findMany"],
  }),
);

The docs could mention that if a primaryKey isn't specified, then the full model is deleted from cache after any mutation, otherwise the mutation will only delete queries that match the model and primaryKey. I think it makes sense to fully flush the model cache by default instead of checking for the "id" property specifically by default. I like the idea of default fallbacks not just for the cacheTime, I can't think of any downside to allowing excludeCacheMethods to be specified per model. What do you think?

from prisma-redis-middleware.

Asjas avatar Asjas commented on May 18, 2024

I added Basic Cache Invalidation in version 1.1.0.

I'm basically searching the Redis cache for all keys that matches a model when a Prisma mutation action happens. I then delete all those keys from Redis.

model in this case would be User, Post or similar.

const keys = await redis.keys(`${model}:*`);
const deletedKeys = await redis.del(keys);

So if create or updateMany is called on the User model, all cached keys that refer to the User model will be deleted.

from prisma-redis-middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.