is there still no option to manually invalidate the cache?

with accelerate, is this even in development?
3 Replies
Ankur Datta
Ankur Datta4mo 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
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 Datta4mo 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 🙏🏾 .