The Cache Lifespan in the Cache tab feature will set the maximum age a cached page can be.
How does it work?
WP Rocket will check the cache files' creation every hour. If at any of those hourly checks, WP Rocket detects that a cache file is "older" than the current Cache Lifespan value, then WP Rocket will delete it, and re-create it if the Preload is enabled.
The cache files that are removed after the Cache Lifespan check are the ones located at /wp-content/cache/wp-rocket/yourdomain.com/.
However, these actions don't apply for the minified files located at the /wp-content/cache/min/1/ folder.
Which value should I use?
Heads up: The Cache Lifespan just can be set globally affecting all of your pages. It can't be set on specific pages with different values.
- Cache Lifespan feature will not work on hosting platforms where WP Rocket caching is disabled, such as WP Engine, Kinsta, WordPress.com, etc. For the full list check Hosting Compatibility article.
- The hourly check is done using a cron job named rocket_purge_time_event.
An admin notice regarding a Scheduled Cache Purge failed task can appear when:
- The cron task runs out of schedule due to a long queue of other cron tasks or WP Cron not being triggered. However, the event should run at later time. This should be treated as a false positive warning.
- WP Cron is not working properly. See more.
When to use this feature
A common example of when the Cache Lifespan feature is useful is when there's a widget on most or every page of your site and you want to refresh its content every given hours.
Note: Using a very short Cache Lifespan can cause CPU overload due to very frequent cache files generation when WP Rocket's Preload is enabled. If you need to refresh a page's content very frequently we recommend using a cron job, and set a higher Cache Lifespan value for your site in general.
Also, if you're managing a website which content only require updates on a monthly or yearly basis - basically static websites - you could set a Cache Lifespan value of several days.