After login. I'm adding one sidebar block. Once I clear cache then only updates variable or it's value.
namespace Drupal\test_demo\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides 'Sidebar' Block
*
* @Block(
* id = "sidebar_block",
* admin_label = @Translation("Sidebar Block"),
* category = @Translation("Sidebar Block"),
* )
*/
class SidebarBlock extends BlockBase {
public function build() {
return [
'#markup' => $this->t('Sidebar'),
'#cache' => [
'max-age' => 0,
]
];
}
}
In mytheme.theme
function theme_preprocess_block(array &$variables) {
echo $variables['elements']['#id'];
}
How can I stop that block to being cached. So once I refresh the page. It loads the value immediately.