Agent Wranglers

MED-21Required

Purge cached copies when a file is deleted or removed

When a file is deleted, erased or taken down, purge its addresses and every derived file from the CDN in the same job. Close the request only after the purge is confirmed.

How to do it

A CDN keeps serving its cached copy until it expires, and a versioned file may be cached for a year. An erased photo or a removed infringing video then stays online. GDPR Article 17 asks for erasure without undue delay. Article 6 of the Digital Services Act keeps a host free of liability only if it removes illegal content expeditiously once it knows. Tag every cached response with its file ID, such as a cache tag or surrogate key, so one call clears every rendition. Delete from storage first and purge second, so the CDN cannot fetch the file again. Retry a failed purge and alert after 3 failures. The storage side is Delete files when their owner is deleted. Takedowns arrive through Take notices about illegal content and answer each one.

Examples

JavaScript example

const MAX_PURGE_ATTEMPTS = 3;

export async function removeFileEverywhere(fileId, { deleteObjects, purgeCacheTag, alert }) {
  await deleteObjects(fileId);
  for (let attempt = 1; attempt <= MAX_PURGE_ATTEMPTS; attempt++) {
    if (await purgeCacheTag(`file-${fileId}`)) return true;
  }
  await alert(`CDN purge failed for file ${fileId}`);
  return false;
}

Python example

MAX_PURGE_ATTEMPTS = 3

def remove_file_everywhere(file_id: str, delete_objects, purge_cache_tag, alert) -> bool:
    delete_objects(file_id)
    for _ in range(MAX_PURGE_ATTEMPTS):
        if purge_cache_tag(f"file-{file_id}"):
            return True
    alert(f"CDN purge failed for file {file_id}")
    return False

How to check

Load a public test image and its thumbnail through the CDN, so both are cached. Delete the file. Within 5 minutes both addresses answer 404 or 410 from every CDN region tested, and the job log shows the purge confirmed.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/files-and-media/serving-files/cdn-purge-on-delete">Agent Wranglers files and media playbook</a>. In code you write, add a comment next to it with the same link.