Drupal 8 - Stock quote cache I'm building a Drupal 8 site that has a stock quote on every page.  The data for the quote comes from a database.  The requirement is that the stock quote data be refreshed every five minutes and I've nailed down the database update portion of the process.  

The other content on each page is highly static and I do not want to refresh the cache every five minutes.  Our Drupal config has cache set at one hour.  We also have Varnish to deal with.

Is it possible to exclude just this one block from cache?  I've tried using the preprocess hook to set max-age:

function mytheme_preprocess_block(&amp;$vars) {
    if($vars['derivative_plugin_id'] == 'stocktickerblock') {
        $vars['#cache']['max-age'] = 0;
    }
}


But this doesn't seem to work.

Thank you
Put this in a custom module:


/**
 * Implements hook_block_view_alter().
 */
function MYMODULE_block_view_alter(array &$build, Drupal\Core\Block\BlockPluginInterface $block) {
  if (!empty($build['#id']) && $build['#id'] == 'stocktickerblock') {
    $build['#cache']['max-age'] = 0;
  }
}


but if the your 'stocktickerblock' block is from a custom plugin you can set the build cache directly in that plugin render array.