How to add cache contexts to a region How can I add cache contexts to a region. I have been able to do this to my blocks but have noticed that parts of the region remain cached.
You can add a cache context to a region the same way as to any other page element:

function mytheme_preprocess_region(&amp;$variables) {
  if ($variables['region'] == 'myregion') {
    $variables['#cache']['contexts'][] = 'user';
  }
}


But this is probably not what you want, because regions are not cached. Usually the blocks inside a region are cached and the complete page which contains the regions. The cache context of the region will only have an effect on higher level elements, not downwards.