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' => $this->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.