Using cache keys
Cache keys let you tag cached responses with arbitrary identifiers and later purge every response sharing a tag in a single request. They’re the right tool when you want to purge a category of content rather than a specific URL — for example, every page belonging to a particular environment, release, content type, or module.
How it works
Section titled “How it works”- Your origin emits a
Cache-Keysresponse header on responses you want to tag. The value is one or more space-separated keys. - QuantCDN tags the cached object with those keys (after hashing them against your project’s namespace) and strips the header so it never reaches the client.
- Later, you
POST /v1/purgewith the sameCache-Keysheader set, and every cached object tagged with any of those keys is invalidated.
# Example origin responseHTTP/1.1 200 OKContent-Type: text/htmlCache-Control: public, max-age=3600Cache-Keys: env:production release:1.4.2 module:linkitProperties to know
Section titled “Properties to know”Matching is exact, not wildcard
Section titled “Matching is exact, not wildcard”env:test purges everything tagged exactly env:test. There is no prefix matching — env: will not match env:test, and env:* is treated as a literal string, not a glob. Plan your key names accordingly: if you want to be able to purge “everything related to env X”, emit a single shared key like env:test on every response in that environment.
Keys are isolated per project
Section titled “Keys are isolated per project”You don’t need to namespace your keys with your project name. QuantCDN hashes every key against your organisation and project before storing it in cache metadata, so a key like env:test from your project cannot collide with the same string from another customer’s project. The hashing happens at both ingest and purge time, using your authenticated Quant-Token’s organisation and project — so an attacker cannot forge a key that targets a project they don’t have credentials for.
There is no discovery API
Section titled “There is no discovery API”QuantCDN does not currently expose a way to list the cache keys associated with a project or URL. Keys are something you define on your side as a convention — track them in your origin codebase, deployment scripts, or wherever else fits your workflow.
Purges are asynchronous
Section titled “Purges are asynchronous”POST /v1/purge returns immediately with {"status": "accepted"} (or {"status": "success"} for AWS-hosted projects). The actual edge invalidation completes in a few seconds. Don’t rely on the response to mean “cache is empty” — treat it as “purge request accepted.”
Recommended pattern: per-environment purging
Section titled “Recommended pattern: per-environment purging”A common situation: a single QuantCDN project hosts multiple environments (e.g. test.example.com and www.example.com), and you want post-deploy purges in CI to scope to only the environment that was deployed.
The clean solution is to have each environment’s origin emit an identifying cache key:
# Test environment responsesCache-Keys: env:test
# Production environment responsesCache-Keys: env:productionThen your CI purges only the matching key:
- name: Purge test cache if: github.ref == 'refs/heads/develop' uses: quantcdn/purge-action@v7 with: customer: ${{ secrets.QUANT_CUSTOMER }} project: my-project token: ${{ secrets.QUANT_TOKEN }} cache_keys: env:test
- name: Purge production cache if: github.ref == 'refs/heads/main' uses: quantcdn/purge-action@v7 with: customer: ${{ secrets.QUANT_CUSTOMER }} project: my-project token: ${{ secrets.QUANT_TOKEN }} cache_keys: env:productionYou can extend the same pattern for any axis you want to be able to purge along: release version, content section, feature flag, etc. Stack multiple keys in one header:
Cache-Keys: env:production release:1.4.2 section:blogA single purge for any of those keys then invalidates this response.
Emitting Cache-Keys from common origins
Section titled “Emitting Cache-Keys from common origins”Drupal
Section titled “Drupal”If you use the Quant Drupal integration, the quant_purger module already maps Drupal’s cache tags onto the Cache-Keys header for you.
Next.js / custom Node
Section titled “Next.js / custom Node”Set the header from your route handler or middleware:
export async function GET(request: Request) { return new Response(html, { headers: { 'Content-Type': 'text/html', 'Cache-Control': 'public, max-age=3600', 'Cache-Keys': `env:${process.env.NODE_ENV} section:products`, }, });}Static sites with a build-time header injector
Section titled “Static sites with a build-time header injector”Static hosts that emit per-file headers (e.g. _headers files, hosting configs) can include Cache-Keys alongside cache-control:
/products/* Cache-Control: public, max-age=3600 Cache-Keys: env:production section:productsWhat to do next
Section titled “What to do next”- Purge via the API — the full
POST /v1/purgereference, including soft purges. - Purge via the dashboard — when you want to purge interactively.
- Deploy via CI/CD — wiring purges into a GitHub Actions workflow.
