Drupal 8.4+ block cache issue


I have an issue with block beign cached for anonymous users. It does not happen on my site that still uses Drupal 8.3.7, but on the other site with Drupal 8.4.4 it does.

The problem is that I have a countdown block written by me in a custom module, it counts down time from current timestamp to the chosen date.
The code for rendering the block looks like this:

$build['countdown_block'][] = [
  '#theme' => 'countdown',
  '#granularity' => [
    'days' => $this->t('days'),
    'hours' => $this->t('hours'),
    'minutes' => $this->t('minutes'),
    'seconds' => $this->t('seconds'),
  '#attached' => [
    'library' => [
    'drupalSettings' => [
      'countdown' => [
        'start' => time(),
        'finish' => $this->configuration['finish_date']

public function getCacheMaxAge() {
  return 0;

I added the getCacheMaxAge method but it does nothing. As soon as user gets on a page it caches the one timestamp for him, and each refresh it keeps countng from the old timestamp, the time() variable doesn’t refresh in drupalSettings in js.

What can I do to not cache this block completly, without disabling all the caches?


Drupal version: 

Source: https://www.drupal.org/taxonomy/term/22/feed