I've built a custom block using BlockBase
and as the content this block displays is different depending on the URL it's accessed via (a query parameter is passed in the URL) this block needs to either not cache, or cache relative only to the specific URL it's accessed using.
I've tried the following:
return array(
'#theme' => 'testing_block',
'#testBlockData' => $testBlockData,
'#cache' => array(
'contexts' => array('url.path'),
),
);
Which doesn't work. So then I tried this:
return array(
'#theme' => 'testing_block',
'#testBlockData' => $testBlockData,
'#cache' => array(
'max-age' => 0,
),
);
This also didn't work, so I tried the two cache settings combined together:
return array(
'#theme' => 'testing_block',
'#testBlockData' => $testBlockData,
'#cache' => array(
'contexts' => array('url.path'),
'max-age' => 0,
),
);
None of these work, and I can't for the life of my figure out why. According to everything I've read, this is the right way to do it.
Is it actually possible to set a block like this not to cache in Drupal? And if so, what am I doing wrong?