A lightweight caching and revalidation library for Cloudflare Workers, using the Cache API and waitUntil for background revalidation. Version 0.11.5 is the latest stable release, with monthly updates. Key differentiators: stale-while-revalidate pattern, deduplication via Cache API markers, optional Durable Objects for guaranteed single-flight, and built-in Hono integration. Unlike TanStack Query, it is purpose-built for Workers with no external dependencies except Hono (v4+). Supports probabilistic stampede prevention and fine-grained retry logic.
npm install cf-workers-queryNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage of createQuery to fetch, cache and revalidate user data in a Cloudflare Worker.
Set gcTime to a positive integer (in seconds) to enable caching.
Always use seconds for staleTime and gcTime, milliseconds for retryDelay.
Add optional Durable Object binding and import the QueryDeduper class.
Do not set queryKey to null; omit it or provide an array.
Omit revalidateMode or set to 'default'.
Run `npm install cf-workers-query` in your project directory.
Change to `import { createQuery } from 'cf-workers-query'` and ensure your package.json has "type": "module".Add [[durable_objects.bindings]] with name and class_name in wrangler.toml, and declare the DO class in your worker.