Many of us have experienced this cache directory “problem.”
We love our WordPress optimization and caching plugins, but occasionally they run amok, doing all sorts of nasty things, like causing backup scripts to simply fail without a whimper, or cause the hosting company to grumble about your space or files usage.
This has happened to me more times than I can count. I recently received an email from a client’s hosting company regarding excess files usage and possible account suspension. Turns out it was my fault. I had installed one of my favorite optimization plugins but hadn’t expected the plugin to eat up 18 gigabytes of space in a matter of weeks (in the form of cache files). Geez!
To make a long story short, I didn’t want to drop my favorite plugin, nor did I want to get yelled at again, so decided to take matters into my own hands. Turns out the problem wasn’t a difficult one to tame.
I simply used the hosting company Cron Job control panel to periodically clear the caching directory. Voilà! – problem solved.
Here’s how I did it.
First, you’ll need to find your web hosts Cron Job settings page.
In this case, cPanel was my go-to, though the setup process should be roughly the same no matter where you host.
The final command was fairly simple:
find /home/username/public_html/username/wp-content/cache/ -mtime +7 -delete
Read backwords, because apparently that’s how programmers think:
“delete files more than 7 days old in directory /wp-content/cache/”
And here is the command broken down:
Food for thought…
Clearing cache files is just one of many things you can automate with cron on your web server. You may even use cron jobs to run wp-cron.php independent of page loads for better performance.
And mucho thanks to a few folks who helped me in reading and editing: Sarah Dilks, Mike Dudas, Joyce, Elizabeth Pampalone, and a few other wandering minstrels.