Skip to content

[Cache] The namespace keys is "APP_DEBUG dependent" #39175

Closed
@maidmaid

Description

@maidmaid

Symfony version(s) affected: 5.1.2

How to reproduce

$ APP_DEBUG=0 bin/console cache:pool:clear cache.app 
// "SCAN" "0" "COUNT" "1000" "MATCH" "wu1MerR6oe:*" (redis-cli monitor)

$ APP_DEBUG=1 bin/console cache:pool:clear cache.app
// "SCAN" "0" "COUNT" "1000" "MATCH" "nonmBNxiVY:*" (redis-cli monitor)

Possible Solution

We can see below that the namespace keys is generated from the class name of the cache adapter.

$name = $tags[0]['name'] ?? $id;
if (!isset($tags[0]['namespace'])) {
$namespaceSeed = $seed;
if (null !== $class) {
$namespaceSeed .= '.'.$class;
}
$tags[0]['namespace'] = $this->getNamespace($namespaceSeed, $name);

In the CacheCollectorPass, this class can be decorated by a TraceableAdapter in debug mode. Once decoracted, the namespace changes.

if ($container->getParameter('kernel.debug')) {
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
$container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions