Cloudflare Worker Edge Cache Key Normalizer
30 Production Challenge Scenarios • Real-Time Automated Quality Scoring
Interactive Prompt Engineering Lab
Test and score your prompts against real-world enterprise scenarios. Get immediate 4-axis quality telemetry, negative guardrail verification, and golden reference prompts.
1. Authoritative Persona
Expert role + zero fluff
2. Deterministic Schema
XML tags + JSON / keys
3. Negative Guardrails
NEVER / fallback rules
4. Token Efficiency
150–1,800 chars concise
Web & System ArchitectureStaff
Cloudflare Worker Edge Cache Key Normalizer
Write a Cloudflare Worker edge script that normalizes query parameters, strips marketing tracking cookies (utm_*, fbclid), and constructs a canonical cache key to maximize global Edge Cache Hit Ratio.
Target Input Context / Untrusted Data:
Incoming Traffic: 25,000 req/sec across 200 edge PoPs Problem: Cache Hit Ratio is only 41% because identical URLs have rearranged query strings (?b=2&a=1 vs ?a=1&b=2) and unique tracking parameters (?utm_source=adwords) Goal: Elevate Cache Hit Ratio to 85%+ without breaking authenticated user sessions.
Quality Requirements & Guardrails:
Define a Principal Edge Infrastructure Architect persona.
Sort all query parameters alphabetically to eliminate key permutation misses.
Strip all blacklisted query parameters (utm_*, gclid, fbclid, _ga).
Use Cloudflare Cache API (caches.default) with custom normalized Request cache key.
Your System Prompt Draft
90 chars~23 tokens
Golden Reference Architecture (100% Quality Benchmark)
<system_instructions>
You are a Principal CDN & Edge Computing Architect.
Write a Cloudflare Worker script in TypeScript that standardizes incoming HTTP requests into canonical Edge Cache Keys.
EDGE CACHING DIRECTIVES:
1. QUERY PARAM NORMALIZATION:
- Strip all analytics tracking parameters (`utm_*`, `fbclid`, `gclid`, `mc_eid`).
- Alphabetically sort remaining query parameters so `?color=blue&size=m` and `?size=m&color=blue` resolve to the exact same cache entry.
2. EDGE CACHE LOOKUP:
- Check `caches.default.match(canonicalRequest)`.
- On cache miss, fetch from origin with `cf: { cacheTtl: 86400, cacheEverything: true }`, store in edge cache asynchronously via `ctx.waitUntil()`, and return response with custom `CF-Edge-Hit: HIT|MISS` header.
3. Output implementation inside <edge_worker> tags.
</system_instructions>