Skip to content

PluginManagerSetsCacheBackendRule and $misnamedCacheTagWarnings over-grabby? #199

Open
@bronius

Description

@bronius

I am grappling with PluginManagerSetsCacheBackendRule giving the message "<tag> cache tag might be unclear and does not contain the cache key in it"

As an example (and what I'm puzzling through), the contrib module graphql^3.x presents a few plugins, each with:

$this->setCacheBackend($cacheBackend, 'subscriptions', ['graphql']);
$this->setCacheBackend($cacheBackend, 'mutations', ['graphql']);

...etc.
(ex. https://github.com/drupal-graphql/graphql/blob/8.x-3.x/src/Plugin/SubscriptionPluginManager.php#L57)

In this case, it looks like the author's intent is to be able to invalidate caches across all the plugins the module provides, and setting such a generic cache tag looks sensible. Analysis with phpstan says, "graphql cache tag might be unclear and does not contain the cache key in it." I see that a few modules in Core do this as well (ex. workflows https://api.drupal.org/api/drupal/core%21modules%21workflows%21src%21WorkflowTypeManager.php/9.2.x which also reports the same phpstan message)

The only way I found to "overcome" this message was to make the cache tag more specific (like graphql_subscriptions or graphql:subscriptions, for instance), which defeats the author's intent, I believe. In fact, it feels like maybe the spirit of the check would be satisfied if instead of checking whether tag contains key, we check that key contains tag (in this case)? Ex. Key could be graphql:subscriptions, and tag remains just graphql.

Please help me understand what I could do to make the world a better place :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions