Purge tools for every plan

Cloudflare is making all cache purge methods available to every customer, regardless of plan type. The change, which was first teased during Birthday Week 2024, removes a longstanding restriction: purge by URL and purge everything were previously the only options outside Enterprise plans. Now, purge by hostname, purge by tag, and purge by prefix are also universally available.

This expansion is made possible by the Instant Purge pipeline that Cloudflare has been building over the past few years. The company reports that the new system maintains sub-150 ms invalidation times even under increased load. Enterprise customers are also seeing significantly raised default purge rate limits, enabled by the greater throughput of the re-architected platform.

Rebuilding the purge pipeline

The effort began in late 2022, driven by the challenge of propagating purge requests across Cloudflare's network of data centers in over 335 cities worldwide. Because cached content can be distributed across all of these locations, each purge command must quickly reach every data center holding that content, locate the affected objects, and invalidate them before stale responses are served.

The scale of invalidation varies widely, from a single file to everything associated with a hostname. Handling that range consistently while tolerating data center outages and network interruptions required a shift from the previous architecture.

Early on, the purge system scaled adequately, but rapid customer growth created a storage bottleneck: millions of daily purge keys consumed cache space. Attempts to smooth traffic spikes with queues and batching introduced latency, without solving the fundamental coupling of usage and storage cost. The original approach — lazy purge, where content is marked expired but left on disk until eviction — was fast but inefficient. Cloudflare considered global or data center-level indexing for purge keys, but deemed the added complexity and latency unsuitable for a network of that size.

The solution was per-machine indexing. Cloudflare selected RocksDB, an embedded key-value store, as the basis for CacheDB, a Rust-based service running alongside each cache proxy. CacheDB handles indexing and immediate purge execution, replacing lazy purge with active invalidation. Local queues buffer purge operations to maintain consistent throughput, and the updated distribution pipeline broadcasts purges directly to CacheDB instances. The result: a 10x reduction in storage requirements and freed disk space, which improves cache retention and HIT ratios while reducing origin egress.

Choosing the right purge method

With more tooling available, the question of what — and how aggressively — to purge becomes more relevant. Overly broad purges can overwhelm origins with requests, while insufficient purging leaves visitors with outdated assets. Cloudflare supports five methods to address this:

  • Purge Everything: Clears all cached content for a website.
  • Purge by Prefix: Targets URLs sharing a common prefix, such as a directory path.
  • Purge by Hostname: Invalidates content for specific hostnames.
  • Purge by URL: Precisely invalidates individual URLs.
  • Purge by Tag: Uses Cache-Tag headers to invalidate grouped assets, providing flexibility for complex scenarios.

All methods are available in the Cloudflare dashboard under the Cache tab's configurations section, or programmatically via the Cloudflare API. Purge requests should specify the appropriate keys — URLs, hostnames, prefixes, or tags. Batching multiple keys into a single request is recommended over one request per key for better throughput.

Rate limits per plan

The rate limits for purge by tag, prefix, hostname, and purge everything now vary by plan type, using a token bucket system applied per account. Each account has a bucket with a maximum size defined by its plan. When a request arrives, tokens are added based on elapsed time divided by the refill rate; if at least one token exists, it is spent and the request proceeds. The refill rate governs steady-state throughput, while bucket size allows for bursts.

As an example, a free plan account starts with a bucket of 25 requests and refills at 5 requests per minute (one every 12 seconds). Sending 26 requests at once processes the first 25; the 26th is rate-limited and requires a 12-second wait before retry.

Continued optimization ahead

Cloudflare says work on the purge platform is not finished. The current P50 for single-file purge is around 250 ms, and the company believes it can be brought under 200 ms with further tuning. The team also plans to enhance throughput across all purge systems and implement additional filtering techniques as usage grows.