wetchn - Worker-Fetchication is a library that provides AsyncLocalStorage based cache for Cloudflare Workers.
You need to enable nodejs_compat flag on your wrangler.toml or wrangler command. See also: Cloudflare Docs
compatibility_flags = [ "nodejs_compat" ]
This library provides cache system like Next.js fetch function.
https://nextjs.org/docs/app/building-your-application/data-fetching/caching
See Example.
This library also provides function cache like React cache.
See Example.
- Fetch remove duplicate
- Perfectly designed
- Function
- Base system by AsyncLocalStorage
- Cache by name
- Load cache by name
- Write document
- Function cache
- Perfectly designed
- Function
- Base system by AsyncLocalStorage
- Caching
- Write document
- CI/CD
- Document
- Fetch cache and revalidate system
- use cache
- use kv
This is proposal. issue is welcome.
import {createWetch, createWache} from "wetchn"
import {KvWetchService} from "wetchn/wetch"
import AsyncLocalStorageWacheService from "wetchn/wache"
const {wetch, etch} = createWetch(KvWetchService.create())
const {wache} = createWache(AsyncLocalStorageWacheService.create())
const cachedFn = wache(() => {
return crypto.randomUUID()
})
export default etch({
async fetch(req) {
const resp = await wetch("https://example.com")
const resp2 = await wetch("https://example.com") // same as resp and no fetch call until calling revalidatePath
const uid1 = cachedFn()
const uid2 = cachedFn() // same as uid1 per a request
return new Response("abc")
}
})