I am using dynamic tokens in page title, which is always being cached. I want to stop that.

I have try by disabling page cache using

function hook_preprocess_page(&$vars) {
  $vars['#cache']['max-age'] = 0;

But they didn't help me, Is there a way so i can only disable or refresh page title cache of a specific page.

My title looks like " lorem ipsum [mydynamictoken:subtoken] "

2 Answers 2


This code works, but you need to place it in the title block.

I wouldn't use the page cache kill switch though, uninstall the module Internal Page Cache instead and then the dynamic page cache can still cache pages where uncacheable blocks are placeholdered.


Disable cache for a custom page from route declaration. If you want to disable cache for a custom controller (Custom module), You have no_cache option (YOUR_MODULE.routing.yml). Example : File : mymodule.routing.yml

  path: '/mymodule/mypage'
    _controller: '\Drupal\mymodule\Controller\Pages::mypage'
    _title: 'No cache page'
    _access: 'TRUE'
    no_cache: 'TRUE'

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.