Inject cache_tags.invalidator instead of using Cache::invalidateTags()

Created on 23 December 2014, over 10 years ago
Updated 30 July 2025, 3 days ago

Problem/Motivation

#918538: Decouple cache tags from cache bins β†’ makes Cache::invalidateTags() a simple wrapper for \Drupal::service('cache_tags.invalidator')->invalidateTags($tags);

As a follow-up, we could look into injecting this into services instead of calling out to the static method. That should allow us to simplify unit tests that currently need to set up a container.

Proposed resolution

Inject into new services and existing standalone services that are not commonly subclassed. (E.g., changing default plugin manager would be a bad idea at this point).

Remaining tasks

User interface changes

API changes

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component

cache system

Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Still a valid task?

  • πŸ‡¬πŸ‡§United Kingdom catch

    The discussion in #31-34 still stands, the entity handlers can't use dependency injection still.

    However, there is no real reason for Cache::invalidateTags() to exist as a wrapper - the static method predates the \Drupal class iirc. We could deprecate that and use \Drupal::service('cache_tags.invalidator')->invalidateTags($tags); in those places, and use injection everywhere else.

Production build 0.71.5 2024