Edge Caching

EdgeWrap caches GET responses globally and serves them directly from edge nodes without hitting your origin. Configure caching defaults and per-path cache policies.

Dashboard Setup & Configuration

You can configure edge cache settings directly inside the EdgeWrap Dashboard:

  1. Navigate to your project in the dashboard at https://app.edgewrap.pro.
  2. Go to the Performance page and select the Edge Caching tab.
  3. Toggle the Caching switch to Enabled.
  4. Configure default caching variables: default Time-To-Live (TTL), stale-while-revalidate duration, and vary header rules.
  5. Under Cache Rules, click Add Cache Rule to define custom caching rules or cache bypasses for specific paths.

API Configuration

Alternatively, you can manage your Edge Caching policies programmatically:

Enable caching on your project via API
curl -X PATCH https://server.edgewrap.pro/v1/projects/prj_01jxyz \
  -H "Authorization: Bearer <your_session_token>" \
  -H "Content-Type: application/json" \
  -d '{ "cacheEnabled": true }'
200Success
{
  "success": true,
  "data": {
    "id": "prj_01jxyz",
    "cacheEnabled": true
  }
}

Configure Cache Settings

Set the default TTL, stale strategies, and which request properties are included in the cache key.

ParamTypeDescription
defaultTtlSecinteger (0–86400)How long to cache responses in seconds(default: 300)
maxTtlSecintegerMaximum TTL allowed (per-path rules cannot exceed this)(default: 86400)
staleWhileRevalidateSecintegerServe stale content while fetching a fresh response from origin in the background. Eliminates cache-miss latency.(default: 60)
staleIfErrorSecintegerServe stale content when origin returns an error or is unreachable. Keeps your API up during origin outages.(default: 3600)
varyByHeadersstring[]Include these request headers in the cache key (e.g. ['Accept-Language'] to cache per-language)
varyByQueryParamsstring[]Only include these query params in the cache key (empty = include all)
varyByCookiesstring[]Include these cookies in the cache key
Configure cache settings via API
curl -X PATCH https://server.edgewrap.pro/v1/projects/prj_01jxyz/cache/config \
  -H "Authorization: Bearer <your_session_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "defaultTtlSec": 300,
    "staleWhileRevalidateSec": 60,
    "staleIfErrorSec": 3600,
    "varyByHeaders": ["Accept-Language"],
    "varyByQueryParams": ["sort", "filter", "page"]
  }'
200Success
{
  "success": true,
  "data": {
    "projectId": "prj_01jxyz",
    "defaultTtlSec": 300,
    "staleWhileRevalidateSec": 60,
    "staleIfErrorSec": 3600,
    "varyByHeaders": [
      "Accept-Language"
    ],
    "varyByQueryParams": [
      "sort",
      "filter",
      "page"
    ]
  }
}

Set Per-Path Cache Rules

Override the default TTL for specific paths. The first matching rule wins, evaluated in priority order.

ParamTypeDescription
pathPatternstringGlob pattern to match the request path (e.g. /api/products/*)
ttlSecintegerTTL in seconds. Set to 0 to bypass the cache for this path.
bypassCachebooleanSkip cache lookup and write for this path(default: false)
priorityintegerRule order (lower = higher priority)(default: 100)
Bypass cache for user data
curl -X POST https://server.edgewrap.pro/v1/projects/prj_01jxyz/cache/rules \
  -H "Authorization: Bearer <your_session_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "pathPattern": "/api/user/*",
    "ttlSec": 0,
    "bypassCache": true,
    "priority": 5
  }'

Verify Cache Is Working

Every response from EdgeWrap includes an X-Cache-Status header showing the cache outcome for that request.

# First request — cache miss, fetches from origin
curl -i https://your-project.edgewrap.pro/api/products \
  -H "x-api-key: ek_live_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"

# Look for this in the response headers:
# X-Cache-Status: MISS

# Second request — served from cache
curl -i https://your-project.edgewrap.pro/api/products \
  -H "x-api-key: ek_live_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"

# X-Cache-Status: HIT

Cache Status Values

X-Cache-StatusMeaningOrigin called?
HITResponse served from cache.No
MISSNot in cache — fetched from origin and stored.Yes
STALEStale cache served, refresh happening in background.Yes (async)
BYPASSCache skipped (non-GET, bypassCache rule, or bypass header).Yes
Tip: If you always see MISS, check your varyByHeaders config. Including headers like Authorization makes every request unique, preventing cache hits. Remove them from the vary config, or use bypassCache: true for authenticated endpoints.

Test Cache Key Resolution

Use the Cache Sandbox inside the dashboard to simulate request parameters and view exactly how EdgeWrap resolves the cache key:

Test cache key generation via API
curl -X POST https://server.edgewrap.pro/v1/projects/prj_01jxyz/cache/sandbox-call \
  -H "Authorization: Bearer <your_session_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "method": "GET",
    "path": "/api/products",
    "queryString": "sort=price",
    "headers": { "Accept-Language": "en-US" }
  }'