Setting cache max-age to 0 has no effect on Block built using BlockBase? 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' =&gt; 'testing_block',
    '#testBlockData' =&gt; $testBlockData,
    '#cache' =&gt; array(
        'contexts' =&gt; array('url.path'),
    ),
);


Which doesn't work. So then I tried this:

return array(
    '#theme' =&gt; 'testing_block',
    '#testBlockData' =&gt; $testBlockData,
    '#cache' =&gt; array(
        'max-age' =&gt; 0,
    ),
);


This also didn't work, so I tried the two cache settings combined together:

return array(
    '#theme' =&gt; 'testing_block',
    '#testBlockData' =&gt; $testBlockData,
    '#cache' =&gt; array(
        'contexts' =&gt; array('url.path'),
        'max-age' =&gt; 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?
This is a known problem for anonymous requests, see this issue PageCache caching uncacheable responses (violating HTTP/1.0 spec) + D8 intentionally disabling HTTP/1.0 proxies = WTF.

Until this is resolved, put this trigger in your block build():

\Drupal::service('page_cache_kill_switch')-&gt;trigger();