Query caching
See original GitHub issueIt would be nice if queries would get out of the box support for caching, it’s a pain to make a wrapper since you’d have to make sure the function you create accepts and returns the right types. The syntax could be something like:
const users = await client.user.find({
select: { x: true },
where: { id },
cache: true // defaults to y ms
})
// Custom time
const users = await client.user.find({
select: { x: true },
where: { id },
cache: 60000 // cache for 1 minute / Maybe an options object for custom cache storage keys?
})
The cache could default to memory and a custom solution could be added in schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
datasource cache {
provider = "redis"
url = env("CACHE_URL")
}
Any thoughts? I just read about the middleware API which maybe could be used under the hood to support this feature, manually caching there would cause duplicate code
Issue Analytics
- State:
- Created 3 years ago
- Reactions:103
- Comments:16 (4 by maintainers)
Top Results From Across the Web
What is query caching? How do I cache my query?
Cached Queries are a way for you to build applications with charts and tables that load instantly. A common use case for caching...
Read more >Query Cache - MariaDB Knowledge Base
The query cache stores results of SELECT queries so that if the identical query is received in future, the results can be quickly...
Read more >Query caching in Power BI Premium - Microsoft Learn
Organizations with Power BI Premium or Power BI Embedded can take advantage of query caching to speed up reports associated with a dataset....
Read more >How To Optimize MySQL with Query Cache on Ubuntu 18.04
Query cache is a prominent MySQL feature that speeds up data retrieval from a database. It achieves this by storing MySQL SELECT statements ......
Read more >Query caching | Databricks on AWS
Query results caching: Per cluster caching of query results for all queries through SQL warehouses. To disable query result caching, you can run ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d also love to see an easy way to invalidate the cache, if this is implemented. For example:
Then, if you update a user, for example:
This can probably even happen under the hood without explicit keys, because Prisma knows when
user.update
oruser.delete
are called, it can automatically invalidate any cache foruser.find
, etc. 🧠+1 for official cache middleware support!