Needs work
Project:
Drupal core
Version:
main
Component:
cache system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
23 Dec 2014 at 22:47 UTC
Updated:
30 Jul 2025 at 21:13 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
berdirThat got in...
Comment #2
berdirThis might work as a novice task, if you know a about about services and injection.
Start with just one example, I would suggest Token. inject the service, then call that instead of the static method. You probably need to update unit tests for that class.
Comment #3
berdirAnother thing to consider is performance. The invalidator uses a tagged services approach, so instantiating it will also create all invalidators that are tagged (not the cache bins, though).
Comment #4
sidharthapHere is the initial patch. @Berdir please suggest...
Comment #6
sidharthapworking on it.
Comment #7
sidharthapPatch created from new D8 instance.
Comment #9
sidharthapComment #11
sidharthapComment #12
vlad.n commentedRe-roll.
Comment #15
wim leersThis is not a simple replacement. This is an addition. Therefore out of scope IMO.
This, which is what the patch is doing everywhere, is not injecting. Please inject the service. Otherwise there's no point.
Comment #16
dawehnerThe thing with the injection here is that the cache tags invalidator should not be needed on a normal page request
but just in a really rare circumstances so I'm curious whether its right to initialize them basically on every request, I guess there is no way around that?
Isn't this also an addition?
Comment #17
wim leersMake it a proxy service? Seems very logical.
Comment #18
pwolanin commentedThis seems to be just switching to
\Drupal::service('cache_tags.invalidator')instead of injecting the dependency?Comment #19
andypostYep all places should get service via proper DI
Comment #20
andypostComment #21
radubutco commentedComment #22
bogdan.racz commentedComment #23
radubutco commentedComment #24
radubutco commentedThis is still work in progress, uploading the patch for a possible review.
Comment #25
wim leersLet's see what testbot says :)
Comment #27
wim leersComment #29
mile23There's basically no way this is a novice task.
Especially when you consider that
ConfigEntityBaseis one of the classes we'll be changing here. It inherits fromEntitywhich you must then figure out how to inject services into.Comment #30
mile23Comment #31
andypostLast patch is totally wrong we can inject services into entity classes cos
Node::create()Basically only static calls should be replaced like #12 started
this is no-go for entities
Comment #32
bogdan.racz commentedComment #33
fabianx commentedI think the trick here is to use setter injection instead of changing the arguments.
Comment #34
berdirNo, there is no trick. entities do not support dependency injection.
Comment #49
smustgrave commentedStill a valid task?
Comment #50
catchThe 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.