There are cases when you need to clear the Drupal cache according to a specific schedule, for example, on your site, the template displays the current date and the next day, as a result of page caching, you will see the old date for some time, until it is reset cache.
Displaying the current date in page.html.twig
In page.html.twig, we add the current_date function, in which we specify a pre-created date format.
{% set current_date = date()|date('U')|format_date('date_format_template_name') %}
And already in the desired region we display the date, which will dynamically change:
{{ current_date|placeholder|striptags }}
Setting up scheduled caching in Drupal 10
There are many ways to automate cache clearing, but the most common are the following:
- Configuring cache flushing using the CacheFlush module (available for Drupal 9 at the time of writing, a patch is needed for version 10)
- Set up clearing the cache using Drush and the Cron task scheduler.
We believe that the second option is the most convenient, since there is no need to install additional modules, and all actions will work on the server side.
Cache Cleanup Automation with Drush and Cron
Depending on how the web environment is set up on the server or web host, the installation of Drush is different on a case-by-case basis. Therefore, before you start entering commands, make sure that Composer and Drush are supported on your tariff plan.
We will consider the automation process based on classic Unix hosting with the Cpanel control panel.
Use the command line to navigate to the site's root directory and use the drush status command to find the path to the PHP binary and the Drush script. The url data will be needed to run commands in cron.

Next, you need to go to the task scheduler, configure the frequency of the script execution and enter the command to clear the cache drush cache-rebuild (drush cr).
Examples of Crontab jobs for shared hosting:
cd /home/account_name/domain_project/public_html && /home/account_name/domain_project/public_html/vendor/bin/drush cr
cd /var/www/account_name/public_html/domain && /opt/php/8.1/bin/php /var/www/account_name/vendor/bin/drush cr
You're all set, don't forget to check your cron job using the notification email or log file using the command
> cron_log.txt 2>&1