How do I programmatically set cache age? Drupal 8:

I have the code for a block successfully doing its work and returning it. The block is called "RacerProfile" and it dumps all its content into variable "$pageContent". At the very end it returns the #markup. Ok. Now how do I tell this to invalidate every six hours?

/**
 * Provides a 'Racer Profile' Block
 *
 * @Block(
 *   id = "racer_profile",
 *   admin_label = @Translation("Slider v1 block")
 * )
 */
class RacerProfile extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() 
    {
    // does all the work to make $pageContent via non-drupal database queries 
    return array('#markup' =&gt; $this-&gt;t($pageContent),  );
    }
 }


In other Drupal answers, I've seen "D8 has cache tags and contexts that will automatically invalidate the block if something changes." Ok, my code is checking a second database. There's no way for Drupal to know what's changing over there. (Without checking, obviously.) So how do I add cache tags with specified timeouts? I can't find examples.

Notes:

-Obviously, this is not related to the Maximum Cache age within the admin area of Configuration > Performance > Caching > Page cache maximum age. I don't want this to apply to the entire site, just this block.

-Obviously, this is not related to settings.php in any way either, since again I don't want to have this apply to the entire site, and the various modules will have different timeout requirements.

-The traffic for the site is relatively low volume, so if rendering a thing four times a day even it only needs to be done once a day isn't a problem. Every six hours means that it's changed before people wake up across four time zones. Mostly. ;)

-(edit addition) The block needs to have its cache controlled for anonymous users.
This is all done from the render array itself.  The nitty gritty details are documented in Cacheability of render arrays.

In your case, you need to do something like

return [
  '#markup' =&gt; $this-&gt;t($pageContent),
  '#cache' =&gt; [
    'max-age' =&gt; 86400, // one day in seconds
  ],
];


This uses the #cache entry for the render array, and sets the max-age to be one day.  This is where you would also add in your cache contexts.

As a side note, try to avoid using '#markup'.  Use themeable elements, either though code or Twig.