7

I'm working with a node type that has several custom fields. The values of these fields need to refresh on each page load, but because of Drupal's caching feature, they don't. What is the best way (simplest way) to stop this content type from caching?

2 Answers 2

14

See if http://drupal.org/project/cacheexclude can do it for you. If not you need to create a module that will implement hook_init. Inside of that hook you need to load the node from arg() from there see if the node is of a certian type; if it is disable the page cache.

<?php
  // Get the current active node object if present.
  $node = menu_get_object();
  if (!empty($node) && !empty($node->type) && $node->type == 'page') {
    drupal_page_is_cacheable(FALSE);
  }
?>
-2

For Drupal 8:

// Mark this page as being uncacheable.
\Drupal::service('page_cache_kill_switch')->trigger();
1
  • I put your code in a code block, but really, are you sure about second line? And why do you post 8 solution under 7 question?
    – Mołot
    Commented Dec 11, 2014 at 14:04

Your Answer

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

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