Technical reference
Cloudflare Cheatsheet
Edge compute, delivery, storage, and security platform
Must Know
bash
Create a Worker
npm create cloudflare@latest -- my-worker
cd my-worker
npm run dev
npm run deployjavascript
Worker Handler
Workers use the web-standard Request, Response, and fetch APIs.
export default {
async fetch(request, env, ctx) {
return Response.json({ ok: true });
},
};Storage
Choose the Right Store
Each storage product has different consistency and access characteristics.
R2 -> object and file storage
D1 -> relational SQL at the edge
KV -> read-heavy key/value configuration
Durable Objects -> coordinated state
Queues -> asynchronous deliveryjavascript
R2 Binding
export default {
async fetch(request, env) {
const object = await env.MY_BUCKET.get("reports/latest.pdf");
if (!object) return new Response("Not found", { status: 404 });
return new Response(object.body, { headers: object.httpMetadata });
},
};javascript
D1 Query
Bind input values instead of constructing SQL strings.
const result = await env.DB
.prepare("select id, name from users where id = ?")
.bind(userId)
.first();Caching & Delivery
javascript
Cache Response
Define who may cache a response and how it will be invalidated.
const response = await fetch(request);
const cached = new Response(response.body, response);
cached.headers.set("Cache-Control", "public, max-age=60, s-maxage=3600");
return cached;Cache Safety
Caching can leak data when identity and authorization are ignored.
do not cache private user responses
include representation-changing values in the cache key
set explicit TTLs
plan purge/invalidation
measure hit ratio and stale contentProduction Notes
json
Bindings and Secrets
Use bindings for platform resources and secret storage for credentials.
npx wrangler secret put API_TOKEN
# wrangler.jsonc
{
"r2_buckets": [{ "binding": "MY_BUCKET", "bucket_name": "files" }],
"d1_databases": [{ "binding": "DB", "database_name": "app" }]
}Edge Checklist
Running near users does not remove normal distributed-system failure modes.
set upstream timeouts
bound request and response sizes
validate every input
use structured logs
understand regional cache behavior
handle retries and duplicates
monitor CPU and subrequest limits