You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add easy cache invalidation helper to defineCachedFunction/defineCachedHandler #3935
When using defineCachedFunction or defineCachedHandler in Nitro, manually invalidating cache entries is complex and error-prone. The cache key depends on the function group, name, and often function parameters, requiring users to reconstruct the cache key string for invalidation:
This process is not ergonomic, especially in larger projects or when multiple cached functions exist with dynamic keys.
Proposal:
Add a built-in cache invalidation method, such as .invalidateCache(), to the function returned by defineCachedFunction/defineCachedHandler. This helper would automatically generate the correct cache key (using the provided arguments) and invalidate it, making cache management simpler for users.
This is now available in ocache (used by Nitro v3) — cached functions now have an .invalidate(...args) method and there's a standalone invalidateCache() helper:
Activity
MickL commentedon Mar 16, 2026
I was just about to open the same issue. Setting the key is easy:
Will generate:
cache:nitro/functions:getAccessToken:fancy-key.json(according to the docs)But to invalidate, we have to write the string ourself and hope that it is correct (probably not):
@pi0 Possibly there is already a helper function but it is just not documented?
Btw. If anyone is searching for the key, one can use
await useStorage('cache').getKeys()schplitt commentedon Mar 16, 2026
@MickL
I completely forgot about this.
This can be closed as this will be available soon.
See https://github.com/unjs/ocache
MickL commentedon Mar 16, 2026
What do you mean by "will be available soon"? You mean it will me used within Nitro?
Can we leave the issue open until it is merged and published to npm + docs are updated?
Also, I dont see a function to get the key in ocache, is it not documented?
pi0 commentedon Mar 16, 2026
Nitro v3 already switched to ocache. We need to move this issue there.
MickL commentedon Mar 17, 2026
Here it is: unjs/ocache#4
pi0 commentedon Mar 19, 2026
This is now available in ocache (used by Nitro v3) — cached functions now have an
.invalidate(...args)method and there's a standaloneinvalidateCache()helper:See unjs/ocache#8