Disable cache a custom block for anonymous user
If you want to completely disable caching for the block, use this function in your block class:

  public function getCacheMaxAge() {
    return 0;
  }


I've never found in the documentation why

'#cache' =&gt; [
      'max-age' =&gt; 0,
    ],


doesn't work with blocks but, like you discovered, it doesn't seem to.