Support caches api
ducan-ne opened this issue · 2 comments
My app is using caches with cloudflare but it seems like not supported in hono vite plugin, it shows undefined when I call it
Tried below code but it doesn't work
const { env, dispose, caches } = await getPlatformProxy()
Object.defineProperties(globalThis, {
caches: { value: caches, writable: true, configurable: true },
scheduler: { // To use scheduler.wait API
value: {
wait: () => {
},
},
writable: true,
configurable: true,
},
})
Got TypeError: 'get' on proxy: property 'default' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '#<Cache2>' but got '#<Cache2>')
Any plan to support this api?
Hi @ducan-ne
You are right! I also think Cache API should used on the Vite dev-server.
Any plan to support this api?
I'd like to make it if it's easy. On the other hand, Vite will support Runtime API (which will be renamed to Environment API). Then perhaps we can use actual workerd as runtime, which supports Cache API natively, in our Vite dev server in the future.
So the answer is... If we can do it easily, we'll do it. But, It will be implemented though we don't do that.
@yusukebe yep, I've managed to make it work with below code, hope it'll be useful for someone faced in near future
const { env, dispose, caches } = await getPlatformProxy()
Object.defineProperties(globalThis, {
caches: {
get(): any {
return caches
},
set() {
},
configurable: true,
},
scheduler: { // To use scheduler.wait API
value: {
wait: () => {
},
},
writable: true,
configurable: true,
},
})