Page cache purging is a vital process in the lifecycle of any website powered by a content management system. It involves clearing out the stored (or cached) versions of your web pages, to ensure that users are always served the most recent content.
In large-scale web applications, managing cache purging can become a considerable task due to the sheer amount of data. Powered Cache, an all-in-one WordPress caching plugin, provides solutions to deal with this effectively. This document discusses how to implement page cache purging on a large scale using Powered Cache.
1. Server-side Cron
One approach to handle this is using a server-side cron job. Cron is a time-based job scheduler in Unix-like operating systems. Users can schedule jobs (commands or scripts) to run periodically at fixed times, dates, or intervals.
The following command can be used to find and delete all cache files older than 300 minutes (5 hours):
find /var/www/wp-content/cache/* -mmin +300 -type f -delete
Here’s a quick breakdown of the command:
find: This is the command that will search for files in a directory.
/var/www/wp-content/cache/*: This is the directory where Powered Cache stores its cached files.
-mmin +300: This finds files that were last modified more than 300 minutes ago.
-type f: This ensures the command only targets files and not directories.
-delete: This deletes the files that meet the criteria.
You can add this command to your server’s crontab to run it regularly. This way, any cache files older than the specified time will be automatically deleted.
2. Async Cache Cleaning in Powered Cache 2.3
As of version 2.3, Powered Cache includes a feature called “Async Cache Cleaning”. This feature enables the plugin to perform cache purging in the background.
To enable this feature:
- From your WordPress dashboard, go to “Powered Cache”.
- In the “Misc” tab, look for “Async Cache Cleaning”.
- Check the box next to “Enable async cache clean-up.”.
- Click “Save Changes”.
With this feature enabled, Powered Cache will automatically manage the cache purging process for you. This reduces the server load and ensures a smoother experience for your website visitors.