Open kaitoqueiroz opened 1 week 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.
Discussed in https://github.com/unjs/nitro/discussions/2714