When creating custom blocks, sometimes you need to make sure the block is never cached f.e. when including dynamic links. 

Add the snippet below to your custom block to make sure it is never cached:

class MYCUSTOMBLOCK extends BlockBase {
  /**
   * {@inheritdoc}
   */
    public function build() {
        return array(
            '#markup' => ""
        );
    }
    /**
     * {@inheritdoc}
     */
    public function getCacheMaxAge() {
        return 0;
    }
}

See this video: Block caching explained

More about block caching?

 

 

Saved you some valuable time?

Received 100 so far from 4 kind contributors.