Hello,

In Drupal 7, I had the option to enable/disable block caching at:
/admin/config/development/performance

In Backdrop CMS, however, this option to enable or disable block caching seems to be missing at:
/admin/config/development/performance

Is this setting hidden somewhere else, or does it no longer exist?

I'm having an issue with custom blocks where their content appears to be cached, causing dynamic content such as PHP filter with arg(1) in the code, to be incorrect (retrieved from other nodes instead of the currently displayed one).

Example:
I have a node type Restaurant with restaurant entries.
Alongside, I have a block containing a link to a webform where users can report changes. The link to the webform includes the node-ID of the currently displayed restaurant entry (the webform itself gets the node_ID with $_GET from the URL).

In the custom block, I have something like this:

<?php
  if (arg(0) == 'node' and is_numeric(arg(1))) {
    $node = node_load(arg(1));
    print "<a href=\"/form/change-restaurant?nodenid=" . $node->nid . "\">Update Information</a>";
  }
?>

The $node->nid in the link is often incorrect and is the same across multiple restaurant nodes—so it seems to be cached.

Accepted answer

You can set the caching for blocks if you have a custom module and create your block with hook_block_info(). There's a setting for cache there in the code.

By your example above it seems like you're using https://github.com/backdrop-contrib/php, which has no official release? You'd be safer to create a custom module and put your logic in it.

You can see an example in the book module, in core. There's also an example block here: https://github.com/backdrop-contrib/examples/blob/1.x-1.x/block_example/block_example.module, though it doesn't include the cache setting.

From what I can tell custom blocks are always cached now. That's partly because they are now implemented in quite a different way from Drupal 7. They are part of layouts.

Comments

You can set the caching for blocks if you have a custom module and create your block with hook_block_info(). There's a setting for cache there in the code.

By your example above it seems like you're using https://github.com/backdrop-contrib/php, which has no official release? You'd be safer to create a custom module and put your logic in it.

You can see an example in the book module, in core. There's also an example block here: https://github.com/backdrop-contrib/examples/blob/1.x-1.x/block_example/block_example.module, though it doesn't include the cache setting.

From what I can tell custom blocks are always cached now. That's partly because they are now implemented in quite a different way from Drupal 7. They are part of layouts.