RealComposer
Performance & Edge

Soft TTL

Direct Definition

A soft TTL is an application-defined freshness window that may differ from the Cache-Control header seen by browsers. Edge workers can treat data as logically expired after a soft TTL while still serving the stale copy and refreshing asynchronously, which smooths traffic and reduces cache stampedes without exposing long staleness to clients.

Technical Architecture & Deep-Dive

Hard CDN TTLs alone force either strict expiry or full blocking revalidation. Soft TTL patterns store `fetchedAt` metadata alongside cached JSON in edge KV or cache APIs. After soft expiry, readers get stale instantly while a single flyer refreshes the key.

This pairs naturally with stale-while-revalidate and request deduplication. Soft TTLs must respect business tolerance for staleness on prices, inventory, and auth decisions.

Key Architectural Benefits

Decouples user-facing freshness rules from CDN header strings.
Enables background refresh without blocking user requests.
Reduces stampedes compared with naive hard TTL expiry.

Soft TTL Metadata on Edge Cache

typescript
const SOFT_MS = 60_000;
const entry = await cache.get(key);
if (entry && Date.now() - entry.fetchedAt > SOFT_MS) {
  void refreshInBackground(key);
}
return entry?.body ?? fetchAndStore(key);
REALCOMPOSER EDGE WORKSPACE

Implement Soft TTL at the Edge

Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.

START BUILDING FREE

Frequently Asked Questions

Q:Is soft TTL the same as stale-while-revalidate?

They overlap. stale-while-revalidate is an HTTP directive. Soft TTL is often custom metadata implemented in worker logic alongside standard headers.

Related Architecture Concepts

Ready-to-Use Edge Recipes