Is there a way to disable the render cache, which caches all the nodes by default, for a particular content type X.

I know we can disable the render cache site wide by commenting out

$settings['cache']['bins']['render'] = ‘cache.backend.null’;

in settings.local.php. But this is not a ideal approach for me as I need to disable the render cache only for a particular node type.

Also, I need to disable the cache for both Authenticated and Anonymous users for the content type X.

Any pointers on the same would be very much appreciated.

  • Also, I need to disable the cache for both Authenticated and Anonymous users. - basically, you have no caching at all, at which point the render cache is moot.
    – Kevin
    Mar 28, 2017 at 15:48
  • To what end? What is your goal?
    – Jaypan
    Mar 28, 2017 at 15:52
  • @Kevin I meant this under the context of disabling the cache for both anonymous and authenticated users for a content type X.
    – Taher
    Mar 30, 2017 at 7:07

1 Answer 1


Like you said disabling the render cache site wide is not a good idea. If you need this for one content type you can do this in a view alter hook.

If you want to disable caching for authenticated and anonymous users you have to set cache max-age = 0 and trigger the kill switch for the internal page cache:

function MYMODULE_node_view_alter(array &$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) {
  if ($entity->bundle() == 'article') {
    $build['#cache']['max-age'] = 0;

The same can be implemented in a theme in a preprocess hook.

  • Thank you @4k4 for the detailed answer! This was exactly what I wanted to do. Cheers :)
    – Taher
    Mar 30, 2017 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.