Wednesday, March 25, 2020

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps:

1. Develop Custom TransportHandler

Develop a custom Transport handler to send the test and purge requests to Cloudflare API server. The handler sets up basic authentication with the user/pass from the replication agent's transport config and sends a GET request as a test and POST as purge request. A valid test response is 200 while a valid purge response is 201.

Sample code is here:

2. Create custom dispatcher flush agent

The transport handler builds the POST request body in accordance with Cloudflare's REST APIs using the replication agent properties.

A. Create New Replication Agent at-

      http://localhost:4503/miscadmin#/etc/replication/agents.publish

B. Agent Configuration:

     The Flush agent must be configured with following 3 properties:
     1. The transport handler is triggered by setting agent's transport URL's protocol to "cloudflare://".
        E.g. - cloudflare://api.cloudflare.com/client/v4/zones/{zone-id}/purge_cache
     2. User: The X-Auth-Email value of cloudflare account
     3. Password: X-Auth-Key value of cloudflare account

C. Agent User Id in AEM:


Create a custom service user to control permission what should be allowed to flush CDN cache: cloudflare-flush

Reference: https://api.cloudflare.com/#zone-purge-files-by-url/

No comments:

Post a Comment

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...