1

There is a way to disable the menu cache ?

Context

Drupal 7

I have a custom module that implements hook_menu(). The link is showing up only if a view have results. It's working.

The problem is that I have to clear the drupal cache each time the view changes the number of results because the condition is not triggered anymore.

function gal_custom_menu() {

  $items['exhibitions'] = array(
    'title' => t('Current exhibition'),
    'page callback' => 'gal_exhibition_callback',
    'access arguments' => array('access content'),
  );  

  return $items;
}


function gal_exhibition_callback() {

  $x = views_get_view_result('exhibition', 'page');

  if(count($x)) {
  $path = drupal_get_path_alias('node/' . $x[0]->nid);
  drupal_goto($path);
  } else {
  return FALSE;
  }

}

Do you have any idea how can I disable the menu cache ? Or is it the Views cache ?

Thanks

4
  • anything with hook_menu is cached automatically. I cant recall anything to stop the cache like you can with blocks. See here... api.drupal.org/api/drupal/modules%21system%21system.api.php/… – Collins Aug 11 '16 at 20:38
  • @Collins hook_menu is cached the definition of menu items but not the page callback result. – Jimmy Ko Aug 12 '16 at 0:07
  • I guess it is due to the views cache. You can prove it by displaying the value $x (you can use dpm()) and comment out the code after it. You should always see the same value even the view changed. – Jimmy Ko Aug 12 '16 at 0:10
  • 1
    Yes views also use cache... But why using views to get only one node, and to go to its page ? The best could be to have your own method to get the node from the view criteria. Can you tell us what are the view criteria to select this node? – TytooF Aug 12 '16 at 8:35
1

Good conversation about other things in this code sample, but to make a page loaded through a menu callback skip cache, you can try drupal_page_is_cacheable(FALSE). See: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_page_is_cacheable/7.x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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