Comments (4)
v2.0.0
has been released.
from prisma-redis-middleware.
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.
I know most Prisma actions (queries and mutations) usually include an
id
field in theargs
ornext
return value.I don't know if this is true for all
actions
or alldatabases
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 amodel
AND that match anid
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.
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)
- Cache not beeing updated HOT 2
- INFO & QUESTION HOT 2
- onMiss callback is being triggered multiple times
- Not able to invalidate keys that previously return `null` as value. HOT 3
- Fix documentation to show that cacheTime is in seconds, not milliseconds HOT 1
- `Prisma.$queryRaw` is being cached HOT 2
- Query stuck at high traffic production app HOT 8
- Output validation failed HOT 6
- Support for redis cluster
- Support for Node 19 HOT 1
- Redis storage is not supported in the browser HOT 1
- Feature Request: Update using Client Extensions HOT 3
- prisma query stuck at prisma.$transaction
- Forever Pending Response When Using Limit Filter Inside Transaction HOT 1
- TypeScript type for invalidationTTL error HOT 2
- How is the key defined (r:, k:) HOT 1
- Cache based on model not over-riding default
- Cache doens't invalidate when setting `keyPrefix` option
- Request: Update NPM Package for Nove.js v20 Compatibility
- executeRaw and executeRawUnsafe did not invalidate model caches HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prisma-redis-middleware.