Trying to ensure a menu we are adding links to for each user is updated immediately in modern Drupal

Trying to ensure a menu we are adding links to for each user is updated immediately in modern Drupal

Too long / didn’t read, it seems to always work fine except for the admin / superuser which wasn’t really part of our use case anyway…

Caching just doesn’t make any sense

drupal rebuild invalidated caches drupal cache clear invalidated tags Drupal invalidating tag does not clear cache immediately? drupal 9 clearing menu cache does not update block cache drupal cache clear by tags clear block cache drupal drupal invalidate specific menu cache

https://www.drupal.org/project/drupal/issues/2488918

\Drupal::service(‘plugin.manager.menu.link’)->rebuild();

MariaDB [db]> SELECT tags from cache_menu;

\Drupal::service(‘cache_tags.invalidator’)->invalidateTags([’the.menu.thing’]);

Clear Specific Cache | Drupal.org

https://www.drupal.org/project/colossal_menu/issues/2839715

https://www.drupal.org/project/menu_block/issues/2833076

drupal 8 show block cache tags https://www.drupal.org/project/blocache

Documentation and Tutorials on Caching

https://www.drupal.org/docs/drupal-apis/cache-api/cache-tags

https://www.srijan.net/resources/blog/clear-cache-tag-to-improve-caching-mechanism-in-drupal

https://learndrupal.co.uk/tutorial/drupal-9-invalidate-cache-tags

https://www.drupal.org/forum/support/module-development-and-code-questions/2021-05-26/how-to-clear-caches-after-saving-a

https://www.drupal.org/forum/support/module-development-and-code-questions/2021-05-26/how-to-clear-caches-after-saving-a

https://drupal.stackexchange.com/questions/294839/how-to-clear-the-a-block-cache-programmically

https://drupal.stackexchange.com/questions/246450/how-do-you-clear-menu-caches-programmatically

The Cache Tag Clear module does only that:

https://git.drupalcode.org/project/ctc/-/blob/8.x-1.x/src/Form/ClearTagCacheForm.php

use Drupal\Core\Cache\Cache;
Cache::invalidateTags($tags_arr);

it doesn’t do any more. It doesn’t do anything special to then cache clear the invalidated tags or rebuild the invalidated caches.

It seems my theory that Drupal invalidating tags does not clear cache immediately.

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Cache%21Cache.php/function/Cache%3A%3AinvalidateTags/8.2.x

Lots of issues related to caches and cache tag and cache invalidation and cache clearing that just seem… confusing.

Allow to clear the list of invalidated tags in CacheTagsQueuer [#3293622] | Drupal.org

8 - Tabs: invalidating cache tags does not lead to a rebuild of the tabs - Drupal Answers

Updating menus does not clear the menu block cache [#2839715] | Drupal.org

Clearing cache when a menu link is added or deleted [#2833076] | Drupal.org

Render cache should be cleared when menu link or entity is updated [#2827653] | Drupal.org

8 - How do you clear cache on a block when node of certain bundle added or updated? - Drupal Answers

Use ‘menu’ as cache tag for menus instead of ‘config:system.menu to avoid coupling [#2488918] | Drupal.org