CDN Cache Invalidation Setup: Automation and Strategies

Stale content in cache lives for hours: customers see old prices and terms, and support handles extra tickets. We set up cache invalidation end-to-end — automate purging on publish events, link content dependencies, and establish an update policy. Update delay is reduced from hours to minutes.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

CDN cache invalidation: why stale content lives for hours

An edit was deployed to origin, deployment completed without errors — yet users still receive the previous version of the page for hours.

The reason is not the release: between origin and browser there is a cache with its own time to live, and it does not know that the content has updated. CDN cache invalidation in such a scheme remains a manual operation from the panel, not part of the publishing process.

The root is in version desynchronization. Cache TTL is set as a number: a day for static assets, minutes or hours for markup. Publishing, however, is an event.

While these two entities live separately, every release turns into a lottery: some nodes already serve the new response, some hold the old one, and a particular user sees the version that was cached first.

The cost is measurable, and it is paid not by infrastructure but by support. Complaints about the old version come there, not to engineers, and triage of each ticket starts with the question "did we purge the cache?".

Then come manual resets by URL or by whole zone through a control panel, e.g. Cloudflare, where a typo in the path leaves stale content living on without any signals.

A separate pain — purging the whole zone "just in case": it removes load from cache and dumps traffic onto origin, and the next edit again requires a manual operation.

We'll break down how this is closed: by tying invalidation to publishing, purging by tags instead of zones, and verifying that after deployment all nodes serve the new version.

What purge automation gives: timings, hit ratio, failure share

Automatic purge is built not on full cache clearing but on labels: the build assigns tags to groups of objects — catalog, product page, static assets — and publishing sends only the list of changed labels to the edge.

Full clearing forces the edge to pull all content from origin again, and with frequent releases this is the most expensive operation possible. Tag mode purges dozens of objects instead of millions.

On graphs this is immediately visible: cache hit ratio stops sawtoothing after every release and stays in a corridor close to the upper bound. Load on origin becomes even — spikes disappear when the whole edge simultaneously re-requests the same pages.

Publishing speed changes qualitatively: an edit reaches the user in seconds, not after the object's TTL in cache expires. At the same time, a whole class of failures goes away — the "half-updated release", when the browser receives new markup with old styling or script. Purging related tags as one set closes this desynchronization.

Platforms like Cloudflare can purge by tags almost instantly, but without tagging rules every release turns into a manual list of paths. We describe the tag scheme once — after that purge is called from the build pipeline and does not depend on who exactly ships the change.

Purge methods: by tag, by path, by build version

Invalidation at the edge is not atomic: while the command propagates across dozens of nodes, some visitors receive the fresh object, some the previous one.

Purge precision and propagation speed are inversely related, so choosing a method is choosing the class of failures you are willing to tolerate.

Different adjacent options break differently: by tag — a forgotten tag on a new resource; by path — an unaccounted parameter in the address; full purge — a hit of all load on origin. Below are the boundaries of applicability for each.

Option When suitable What you pay with
Purge by tag one object is included in dozens of pages: catalog, product page, feed every origin response must carry the tag; a missed tag means stuck content until the end of TTL
Purge by path or pattern static assets and pages with predictable address pattern boundaries: parameters in address, limit on number of paths in one request
Build versioning built scripts, styles, fonts previous versions live until end of TTL; a registry of active keys is needed
Full purge emergency case, data error request storm on origin and database degradation; nodes update unevenly

In practice, methods are combined: build version — for static assets, tags — for responses with data, full purge is kept as an emergency lever with separate access rights.

Implementation: from content inventory to purge policy

Cache invalidation is not one call at release time, but a sequence where every step leaves a verifiable result. If you skip inventory or dependencies, after publishing users get a mixture of versions: markup updated, but styles or product data did not. The work order we follow for implementation:

  1. Content inventory. We label everything served through cache: static assets with a version in the name, pages, service responses, media. For each type we record the allowed TTL — result is documented as a table "type — TTL — purge method".

  2. Dependency scheme. We build a map of objects that change together: catalog page and product page, template and shared fragment, feed and its items. Without it, targeted purge leaves incompatible combinations — we get a relationship graph and a list of composite objects.

  3. Purge rule setup. We move from full clearing to targeted: purge by tags, separate rules for paths with parameters, separation of hard and soft mode. Result — rule configuration in version control.

  4. Automation in the publishing pipeline. The purge call becomes a release step and triggers after successful deployment, with retries on failure and protection against duplication. Result — a release step and request log instead of manual purges.

  5. Post-publish verification. We compare version tags and response headers on a sample of nodes in different regions, not just one. Result — automated checks and a consistency report.

  6. Policy and rollback. We describe actions on a failed purge, rate limits, and protection against a request avalanche. Result — a policy and a practiced rollback scenario to the previous version.

Output is not a set of scripts but a manageable process: purge is triggered by publishing, not manually, and confirmed by checks.

Configurations, dependency schemes, and purge policies

The kit is assembled so that the on-call shift can work without us: an engineer opens the document, finds the needed rule, purges the cache, and understands what to check afterward.

Below is what exactly remains in your hands along with configured CDN cache invalidation automation.

  • Cache rule map — which paths and response types are cached, what TTL is set, and which origin headers override it.
  • Dependency scheme — graph "page → template → shared blocks → data", showing what to invalidate when editing one component without clearing the whole domain.
  • Purge policy — procedure for three scenarios: point edit, section release, emergency rollback to the previous version.
  • Request templates — purge by address, by path prefix, and by tag, with ordering and limits to stay within provider quotas.
  • Publishing binding — a rule that triggers purge after static deployment, with protection against repeated triggers when the build step restarts.
  • Verification checklist — reference request, response header comparison, and control on several nodes: how to make sure the object is actually updated.
  • Responsibility matrix — who purges during a routine release, who confirms the result, and who to escalate to when nodes diverge.
  • Cache documentation and incident log — adopted decisions, workarounds, and postmortems of cases when purge did not work on the first try.

Everything lies next to configuration in your repository, with versioning: policy changes go through review just like code.

Case: update delay reduced from hours to minutes

What was

A publication with millions of page views per day kept HTML and static assets on CDN with a long cache TTL. Hit ratio stayed around 60%, origin was calm — until the first urgent publication.

The edit at the edge was seen only after manual purge, and the on-call engineer purged the whole zone: the editorial team waited for updates from 40 minutes to several hours.

The cost of this — a spike on origin. After a full purge, all edge nodes went for the same objects: requests to origin grew multiple times, response time increased, and some ended in an error. They tried not to touch cache during peak hours, so edits accumulated until night.

What changed

They switched to purge by tags: each entity — article, section, template — is assigned a key, and invalidation goes by key, not by addresses.

Static assets with a hash in the name were released with a long TTL and marked "immutable", HTML — with a short TTL and serving a stale copy while the fresh one is pulled.

Purge became a release step: deployment, invalidation of affected tags, confirmation from API, and only then switching the pointer to the new version. We work through Cloudflare — its tag purge API removed manual operations.

What resulted

Update delay fell from hours to tens of seconds: median — about 40 seconds, 95th percentile — less than two minutes. Cache hit ratio grew from 60% to 96%, because long TTLs became safe.

Load on origin at purge time grows within 10–15% instead of a multiple spike: no failures, and rollback to the previous version takes seconds — returning the previous pointer is enough.

How does tag invalidation differ from purge by paths?

Purge by paths is an explicit list of addresses: the application enumerates URLs that need to be removed from cache. Tag invalidation works differently: when served, an object is marked with a set of tags, and one call by tag removes everything tied to it.

The difference is not in response speed, but in who is responsible for list completeness — the application or the cache.

Approach When suitable Limitations
Purge by paths Point edits, a small set of predictable addresses Not atomic: purge goes page by page. The application maintains list completeness; every new address pattern requires updating rules
Tag invalidation Catalogs, feeds, product pages, where one entity is served at many addresses Requires tag support on the delivery side and tagging in the application; there is a limit of tags per object; an error in setting a key quietly leaves a record in cache
Name versioning Static assets: scripts, styles, images, fonts Requires a build where the name changes with content; does not work for addresses that cannot be rewritten

Behavior on partial success differs more than it seems. If one address is missing from the path list — for example, a catalog page with a filter — users see a mixture of versions of different ages, and the discrepancy lasts until the record's TTL expires.

Tag invalidation purges the set as a whole, but a partial result is still possible: an object to which the key was not assigned when served remains in cache and quietly falls out of purge — therefore tags should be checked with the same set of tests as the pages themselves.

With mixed content, approaches do not compete. Static assets are served under versioned names, dynamic pages and fragments are marked with tags, and purge by paths is kept for point edits like a redirect or promo page.

Tags are created by semantic entities — product page, category, feed — so that publishing one object does not purge the whole cache and force origin to rebuild everything.

Questions that come up during purge setup

During setup, doubts come up that are not visible in a demo: can only changed objects be purged, what to do with frequent edits during a promotion, and how it works if content is delivered through several delivery networks. Below are short answers for each point, so the decision can be assessed by risks, not promises.

Purge the whole cache or only part?

A full purge hits the entire cache: the next traffic spike goes to the origin server, and response time grows on all pages, not only the changed one.

Therefore objects are marked with cache tags — by section, page template, or product ID — and on publish only the affected group is purged. An edit to one product page does not affect the catalog and home page.

Are there rate limits on requests?

Yes, and each delivery network has its own. During mass edits — catalog import, nightly rollout — requests are queued, combined, and deduplicated: a thousand changes go as one batch, not a thousand requests.

We add a delay to collapse a series of edits and a separate priority for urgent ones, so we do not hit the limit during a sale.

Content is delivered through several independent networks — what then?

Then purge cannot be launched from one of their panels. A unified control layer is needed: the publish event triggers a broadcast to all networks, each receives its own set of tags, and purge state is recorded — a repeated run does not duplicate work.

Different propagation times are verified by a control object, and only after that is the task considered closed.

Let's discuss your content update scheme

Estimating "from the description" almost always goes off track: the cache purge scheme depends on how content is born, how often it changes, and what is already configured at the perimeter. To calculate based on facts, not assumptions, send the following.

  • content composition: static assets, catalog pages, personalized responses, media — what is cached at the shared level and what is targeted;
  • frequency and nature of edits: planned releases, stream of price and stock updates, urgent content removals;
  • current caching rules: control headers, object TTL, keys by which cache is formed;
  • perimeter request logs for several weeks: cache hit ratio, response codes, most frequent addresses;
  • emergency scenarios: what was published, what content remained stale, how long it lasted, and how it was mitigated;
  • access: perimeter control panel, configuration repository, publishing tools — read access is enough.

In response we will return a breakdown by categories: where a short object TTL is enough, where purge by tag is needed, and where address versioning is needed.

Separately we will show how many purge requests are used during a normal release and during a mass edit, and propose an implementation order with rollback points.