Chapter 8. How-to Guides

Delete Expired Cache on a Schedule

Optimized files and cached pages expire after the Cache lifetime on the General tab. JCH Optimize deletes them on a schedule, once a day unless you change it, together with the cached pages that still use them, so the cache doesn't keep growing. This runs as a scheduled job, never while a visitor is loading a page, and it is set up for you when you install JCH Optimize.

If you use another page cache plugin, you may want to stop deleting expired cache, so pages that plugin cached don't point to files that were deleted.

Joomla

Installing JCH Optimize adds a task called JCH Optimize - Delete expired cache in System → Manage → Scheduled Tasks, which runs once a day. The task is what turns this on and off:

  • To check it runs, look at its Last Run Date in that list, or click Run Task to run it now and see how many files it deleted.

  • To change how often it runs, open the task and change its schedule.

  • To stop deleting expired cache, tick the task, open Actions and choose Disable.

If you had turned off the Delete expired cache setting of earlier versions, updating creates the task disabled. If you deleted the task, create it again with New and choose JCH Optimize - Delete expired cache.

Joomla runs scheduled tasks while your site has visitors (the Lazy Scheduler), unless you set them up to run from your server's CRON. You can also run it from CRON with the jchoptimize:clear-expired command; disable the task then, so it doesn't run twice. If your cache storage is APCu, use the task instead: APCu isn't shared with the command line, so the command can't reach the cache and stops with an error.

Important

On a LiteSpeed server, run the task from the site, with the Lazy Scheduler or Web Cron, not from CRON on the command line. After deleting expired files, JCH Optimize clears LiteSpeed's cache, so it stops serving pages that link to them. LiteSpeed's cache can only be cleared from a page request, not from the command line. With the LSCache plugin installed, runs from the command line therefore keep the expired files (and the pages using them) and say so; the next run from the site deletes them.

WordPress

On the settings page, General tab, choose how often it runs in Delete expired cache: Hourly, Twice Daily, Daily (the default) or Disabled, which stops it. Save. WordPress runs it as the WP-Cron job jch_optimize_clear_expired while your site has visitors. To run it from the command line with WP-CLI:

$ wp cron event run jch_optimize_clear_expired

If your cache storage is APCu, let WP-Cron run it from the site instead: APCu isn't shared with the command line, so a run from WP-CLI can't reach the cache and deletes nothing.

If the cache is too large to check within a minute, all of it is cleaned instead, as if you had clicked Delete Cache. The run is recorded on the Logs page when the Log level is Info.