is there still no option to manually invalidate the cache?

with accelerate, is this even in development?
8 Replies
Ankur Datta
Ankur Datta8mo ago
Hey @sylvester stallone 👋🏾 , To manually invalidate the cache you have to go to the platform console. You can also create add a cacheKey field in your model such as,
model User {
id @id @unique
name String
description String
cacheKey String @unique
}
model User {
id @id @unique
name String
description String
cacheKey String @unique
}
You would have to store the cacheKey in some key value store and update it on every invalidation.
// change cache key value
const updateCacheKey = await updateCacheKey(userId)

await prisma.user.update({
data: {
updateCacheKey,
...otherUpdates
}
})
// change cache key value
const updateCacheKey = await updateCacheKey(userId)

await prisma.user.update({
data: {
updateCacheKey,
...otherUpdates
}
})
During reads,
const updateCacheKey = await getCacheKey(userId)
await prisma.user.findUnique({
data: {
where: {
id: userId,
cacheKey: cacheKey
}
},
cacheStrategy: {
ttl: 100
}
})
const updateCacheKey = await getCacheKey(userId)
await prisma.user.findUnique({
data: {
where: {
id: userId,
cacheKey: cacheKey
}
},
cacheStrategy: {
ttl: 100
}
})
This would guarantee invalidations on every update, even on development. Let me know if this helps!
sylvester stallone
sylvester stalloneOP8mo ago
how would this work on a findMany @Ankur Datta also when is cache invalidation shipping in accelerate? is there an RFP we could trakc?
Ankur Datta
Ankur Datta8mo ago
how would this work on a findMany
It would be a bit tricky with findMany, but it's doable.
await prisma.user.findMany({
data: {
where: {
id: {
in: [1, 2, 3]
},
OR: {
cacheKey: cacheKey // No model would have this cache key, but you can update it regardless, so that Accelerate views it as a different query
// The OR would ensure that the correct data is still returned
}
}
},
cacheStrategy: {
ttl: 100
}
})
await prisma.user.findMany({
data: {
where: {
id: {
in: [1, 2, 3]
},
OR: {
cacheKey: cacheKey // No model would have this cache key, but you can update it regardless, so that Accelerate views it as a different query
// The OR would ensure that the correct data is still returned
}
}
},
cacheStrategy: {
ttl: 100
}
})
Let me know if I need to elaborate 😄 .
Also when is cache invalidation shipping in accelerate? is there an RFP we could trakc?
We have no timelines for this as of yet. I'll let you know once we have something 🙏🏾 .
colhoop
colhoop4mo ago
The cache key method is interesting and probably something I will have to do on some of my queries for now. But I really think a built-in method for invalidating query cache should be near the top of the roadmap's priority list. I would consider a feature like this MVP necessary Also an option to refresh the cache in the background on demand please 🙂
Ankur Datta
Ankur Datta4mo ago
@colhoop we're working on cache invalidation for Accelerate 😄 . Keep an eye on the #announcements channel for any news on this 👀 .
Ved
Ved3mo ago
Hi, any update on this?
Raj
Raj3mo ago
Been waiting on on-demand invalidation since Accelerate was first announced.
Ankur Datta
Ankur Datta3mo ago
Hey @Ved and @Raj 👋🏾 , thanks for letting your interest known. We'll reach out to you once the feature is out 😄 .
Want results from more Discord servers?
Add your server