Cache pages/variables in hook_preprocess() for anonymous user So I am having trouble understanding the caching of variables set in hook_preproccesses for anonymous users. It seems that the entire page is cached, and not rebuilt, even when set to no caching. With the following simplified example I am troubleshooting:

/**
* Implements hook_preprocess_node().
* @param $variables
*/
function hook_preprocess_node(&amp;$variables) {

  $variables['testing_1'] = [
      '#markup' =&gt; date('m/d/Y h:i:s a', time()),
      '#cache' =&gt; ['max-age' =&gt; 0]
  ];

  $variables['testing_2'] = date('m/d/Y h:i:s a', time());
}


then in twig template:

{{ testing_1 }}

{{ testing_2 }}


Both seem to work fine for logged in users, but these variables never seem to update for anonymous users except upon:


Manually clearing cache
Saving content on the node, which then clears node cache.


Even when page caching is set to "no caching" on /admin/config/development/performance, but that does not seem to matter. Its as though the hook_preproccess does not run for anon users once first page hit from anon user happens.

It seems like from Anonymous user cache control and others, this is due to internal page cache module. Uninstalling this DOES solve the problem, but I am unsure that this is the best way to solve this issue, especially since it is enabled by default. Per the docs, internal page cache says "This module assumes pages are identical for all anonymous users". This is true, I simply want the pages to rebuild (rerun the preproccess hook) for ALL anon users when page cache (set on /admin/config/development/performance) clears. 

After a day or so of troubleshooting, I am considering simply creating a cron job to flush caches at this point, but there has to be a better way I am missing. What is the best way to ensure that pages rebuild for anonymous users after a set time?
You may have encountered a core bug where a page cache is not respecting the max-age, or in other words, max-age is not bubbling up to the page cache. There's a workaround on the issue summary but the workaround has a few problems of its own so make sure you consider the implications carefully. The bug issue is postponed until 3 of the linked issues are resolved. Hope this helps.