For Workes & Pages, what is the name of the domain?
What is the issue or error you’re encountering
How to delete unused files after X time of inactivity in Cloudflare R2
What are the steps to reproduce the issue?
Hi everyone,
I’m looking for an efficient way to automatically delete files stored in Cloudflare R2 after a certain period of inactivity (e.g., 1 year without being accessed). Ideally, I’d like to avoid unnecessary reads/writes to keep costs down.
Current Approach:
The alternative I’ve considered is to create a Cloudflare Worker that retrieves the image from R2 and updates the metadata to log when each file is accessed. Then, I’d have a scheduled job that checks for files that haven’t been accessed within the set timeframe and deletes them. However, I’m concerned that this approach might increase costs due to the additional write operations every time a file is accessed.
Question:
Is there a more cost-effective way to manage file deletion based on last access time in Cloudflare R2? Are there any built-in tools or third-party integrations that could help with this use case?
Thanks in advance for any insights or suggestions!