Create a cron job to automatically clear cache I'm trying to clear cache automatically with a cron job but it didn't work.
I'm debugging simply on the browser at this link website-url/cronjob.php.
I think it's a problem with the syntax, I have tried to truncate the tables from database.

As you can see in the code attached below, I've tried two methods, but neither one works.

\Drupal::database()-&gt;truncate('cache_config')-&gt;execute();
mysql_query('TRUNCATE TABLE yqxq_cache_config');
mysql_query('TRUNCATE TABLE yqxq_cache_container');
mysql_query('TRUNCATE TABLE yqxq_cache_data');
mysql_query('TRUNCATE TABLE yqxq_cache_default');
mysql_query('TRUNCATE TABLE yqxq_cache_discovery');
mysql_query('TRUNCATE TABLE yqxq_cache_dynamic_page_cache');
mysql_query('TRUNCATE TABLE yqxq_cache_entity');
mysql_query('TRUNCATE TABLE yqxq_cache_menu');
mysql_query('TRUNCATE TABLE yqxq_cache_render');
mysql_query('TRUNCATE TABLE yqxq_cache_toolbar');
?&gt;


What do I need to change to make this script work?

This is an example of query from the statistics view, which doesn't update if I don't run clear cache.

&lt;?php
$count_users_tot = db_query('SELECT COUNT(uid) FROM {users}')-&gt;fetchField();
print $count_users_tot;
?&gt;
Thanks to @No Sssweat, @kiamlaluno, @Rick B, I've got an answer.
Firstly, I learned that is not a good practice to clear cache automatically every minute or so often.
Secondly, I figured out that I can solve this problem without using a cron job at all, but I have to understand these tag based caching mechanisms.

The problem was as in the image attached below, Page-Caching was Tag Based, so selecting None option solved my issue.