Skip to content

Cache Purge

Invalidate a cached response via the Admin API without restarting the proxy. Dwaar’s in-memory cache stores responses keyed by {method}:{host}:{path}. The PURGE endpoint accepts a host/path pair, reconstructs the GET cache key, and evicts the entry immediately.

Purging is instant — the next request for that URL fetches a fresh response from the upstream.


Terminal window
curl -X PURGE http://localhost:6190/cache/example.com/assets/style.css \
-H "Authorization: Bearer $DWAAR_ADMIN_TOKEN"

PURGE /cache/{host}/{path}

The PURGE method is non-standard HTTP — it is used by Varnish, Squid, and Nginx for cache invalidation and is understood by most HTTP clients.

ComponentDescription
hostThe virtual host as it appears in the cache key (no port suffix)
pathThe URL path, with or without a leading /

The Admin API listens on port 6190 by default. All endpoints except GET /health require authentication.


PURGE

PURGE /cache/{host}/{path}

The host segment is the route domain — the canonical domain from the matched route, not the raw Host header (which may include a port). The path segment is everything after the first / separator.

Examples:

PURGE /cache/example.com/assets/style.css
PURGE /cache/api.example.com/v1/users
PURGE /cache/example.com/

All TCP connections to the Admin API require a bearer token in the Authorization header:

Authorization: Bearer <token>

The token is set via the DWAAR_ADMIN_TOKEN environment variable at startup. Connections over a Unix domain socket (UDS) bypass token auth — access is controlled by filesystem permissions on the socket file.

If DWAAR_ADMIN_TOKEN is not set, all authenticated endpoints (including PURGE) reject requests with 401 Unauthorized.

The Admin API enforces a global rate limit of 60 authenticated requests per 60-second window. Exceeding this returns 429 Too Many Requests.


The cache entry was found and invalidated.

{"purged": true}

The path after /cache/ was empty.

{"error": "missing cache key — use PURGE /cache/{host}/{path}"}

The Authorization header is missing, malformed, or carries an incorrect token.

{"error": "unauthorized"}

The key was valid but the entry does not exist in the cache (never cached, already expired, or already purged).

{"purged": false, "reason": "not found"}

The global request counter for the current 60-second window has been exceeded.

{"error": "rate limit exceeded"}

The proxy was started without cache support. The PURGE endpoint is only available when a cache storage backend is attached to the Admin service.

{"error": "cache not enabled"}

Terminal window
curl -X PURGE http://localhost:6190/cache/example.com/assets/app.js \
-H "Authorization: Bearer $DWAAR_ADMIN_TOKEN"

Expected response:

{"purged": true}
Terminal window
curl -X PURGE http://localhost:6190/cache/example.com/ \
-H "Authorization: Bearer $DWAAR_ADMIN_TOKEN"

When running Dwaar with a UDS admin socket, skip the bearer token — the OS controls access via socket file permissions:

Terminal window
curl --unix-socket /run/dwaar/admin.sock \
-X PURGE http://localhost/cache/example.com/assets/style.css

Check whether an entry exists before purging

Section titled “Check whether an entry exists before purging”

The Admin API does not have a HEAD-style lookup endpoint. If you need to verify cache membership, issue the PURGE and check whether the response is {"purged":true} or {"purged":false}.

The API does not support wildcard or prefix purges — each URL must be purged individually. To purge a set of paths after a deploy:

Terminal window
PATHS=(
"/assets/app.js"
"/assets/style.css"
"/index.html"
)
for p in "${PATHS[@]}"; do
curl -s -X PURGE "http://localhost:6190/cache/example.com${p}" \
-H "Authorization: Bearer $DWAAR_ADMIN_TOKEN"
echo
done

  • Caching — how Dwaar caches responses, cache key construction, TTL configuration
  • Admin API — all Admin API endpoints, authentication, rate limiting, and UDS setup