1

After clearing the cache, Drupal generates cached versions of every node/page that gets visited. Which is fine.

However – if I visit the German version of a node/page, not only the german version will be cached, but also all the translations of that specific node.

(Normally, this wouldn’t be a problem, but I have a custom input filter working which detects the current language and changes things in the text accordingly. This input filter has only access of the current system language, not the language of the currently filtered node. Which leads to wrong results.)

Can I prevent the automatic caching of node translations?

2 Answers 2

2

So there is a function called drupal_page_is_cacheable() which you can call, on a site, in order to avoid the caching, so you could for example call that on your uncachable filter.

1
  • Sounds interesting. Maybe it will fit into the workflow. Let’s see … Commented Feb 20, 2013 at 7:59
1

I had the same problem with node translations being cached. After some backtracing I found that the module responsible for loading and caching translated versions of the node is the Translation core module.

The function translation_node_view implements the node_view hook to create links to the translated versions when viewing a node. There is an option to disable showing these links in the translation options, but this hook will run anyway, causing the translated nodes to load and consequently be cached.

Too fix the problem you have to disable the hook in the translate module. But since hacking the core is not a good option, try instead to 'unhook' it by adding the following function to your own module:

function YOURMODULE_module_implements_alter(&$implementations, $hook) {
    if($hook == 'node_view') {
        unset($implementations['translation']);
    }
}

This code removes the hook from being cached by drupals hook system. Keep in mind that this will completely disable the translated links when viewing a node. If that is not a problem then this solution should work. More info about the affected hook can be found here: translation_node_view

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.