Quantcast
Channel: User anschauung - Stack Overflow
Viewing all articles
Browse latest Browse all 40

Answer by anschauung for how to force drupal function to not use DB cache?

$
0
0

Where are you calling this? For example, are you using it as part of your template.php file, as part of a page, or as an external module?

Unless you have this wrapped in a function with its own namespace, try naming the variable differently than $node -- for example, name it $my_node. Depending on the context, the 'node' name is very likely to be accessed and modified by Drupal core and other modules.

If this is happening inside of a function, try the following and let me know what the output is:

$test_node_1 = node_load(344983); // Any hard-coded $nid that actually existsecho $test_node_1->nid;$test_node_2 = node_load(arg(1)); // Consider using hook_menu loaders instead of arg() in the future, but that's another discussionecho $test_node_2->nid;$test_node_3 = menu_get_object(); // Another method that is better than arg()echo $test_node_3->nid;

Edit:

Since you're using hook_block, I think I see your problem -- the block itself is being cached, not the node.

Try setting BLOCK_NO_CACHE or BLOCK_CACHE_PER_PAGE in hook_block, per the documentation at http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_block/6

You should also try to avoid arg() whenever possible -- it's a little bit of a security risk, and there are better ways to accomplish just about anything arg() would do in a module environment.

Edit:*

Some sample code that shows what I'm referring to:

function foo_block ($op = 'list', $delta = 0, $edit = array()) {    switch ($op) {      case 'list':        $blocks[0] = array('info' => 'I am a block!','status' => 1,'cache' => BLOCK_NO_CACHE // Add this line        );        return $block;      case 'view':       .....    }}

Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>