I read a lot of posts on how to disable caching on a custom block but none seemed to give the perfect solution.
$build['#cache'] = ['max-age' => 0]orpublic function getCacheMaxAge() { return 0; }: Do not seem to work, or at least for authenticated users\Drupal::service('page_cache_kill_switch')->trigger(): Kill the complete page cache, not only the block ones- Lazy builders: Seems to work only for anonymous users
In my case, I have a block which renders a random node and it's clearly an issue while I'm not able to refresh this cache.
So how to set up such a block? (Drupal 8.4.3)
Posts giving not working solutions:
- How to prevent a block from being cached?
- How do I correctly setup caching for my custom block showing content depending on the current node?
Edit:
public function build() { [...] if ($prev_node) { $render_controller = \Drupal::entityTypeManager() ->getViewBuilder($prev_node->getEntityTypeId()); $build = $render_controller->view($prev_node, 'pagination'); $build['#node']->field_custom = 'something'; } return $build; } public function getCacheMaxAge() { return 0; } Thank's to @Clive, it seems my issue is not linked to the block cache itself, but to the entity I render in this block. If so, I have no ideas how on to resolve this issue.
After many searches, D7 cache_clear_all('field:node:10', 'my_field') function seems to do what I want to do. What is its equivalent for D8 ?