Open kaitoqueiroz opened 2 months ago
I'm also facing this problem, no idea how to work around it yet. It seems to me that shouldBypassCache should run every request regardless of other parameters because in it's current state it seems pointless as you cannot bypass cache using it. Same thing goes for shouldInvalidateCache() - runs only when the response wasn't cached yet which makes it unusable (at least i don't see the point of using it in this state).
I've even tried to manually invalidate the cache before the request with an endpoint setup like so:
export default defineEventHandler(async (event) => {
const storage = useStorage("cache");
try {
const cacheKeys = await storage.getKeys("nitro:handlers");
// Remove all cache items concurrently
await Promise.all(cacheKeys.map((element) => storage.removeItem(element)));
return { success: true };
} catch (error: any) {
console.error("Error invalidating cache:", error);
throw createError({
statusCode: error.statusCode || 500,
statusMessage: error.message || "Failed to invalidate cache",
});
}
});
I've noticed it correctly removes the file from the cache folders in nitro but even after running it, my api endpoint still serves cached response.
@kaitoqueiroz I've opened a new issue with a workaround which might work for you, try it out and let me know if it worked.
I'm facing the same problem. I think we may have to use a caching solution other than Nitro however would love to hear if/when there's a fix
I'm facing the same problem. The workaround in #2738 by @dencs08 just saved me. Also, It would be nice if the Nitro Cache Guide included examples using shouldBypassCache
and shouldInvalidateCache
Discussed in https://github.com/unjs/nitro/discussions/2714