LiteSpeed doesn’t automatically clear the VirtualHost-level cache, which can lead to unnecessary storage usage over time. To address this, you can set up a cron job to regularly clear the cache. This guide will walk you through the process.
Steps to Set Up a Cron Job to Clear LiteSpeed Cache:
Access the Server Log in to your server’s command line as the ‘root’ user via SSH or use the “Terminal” in WHM.Open Crontab To edit the cron jobs, enter the following command:
crontab -e
Insert the Cron Job
Press the o key to add a new line in the editor, then enter the following command to create a cron job that will clear cache files older than 30 days:
0 0 * * * LARGE_LSDIR="$(du --threshold=30G -sh /home/*/lscache/ | cut -f2-)"; for ls_path in $LARGE_LSDIR; do echo "Clean up $ls_path"; find $ls_path -type f -mtime +1440 -exec rm -f {} \;; done
Save and Exit
Press the esc key to exit insert mode. Then, type :wq and press Enter to save the changes and close the crontab editor.
By following these steps, your server will automatically clear LiteSpeed cache files that meet the criteria, helping you manage disk space more efficiently.