Skip to content

Psr16Adapter fails to cache any item if a namespace is used #32019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changing namespace separator to _ to match PSR-16 allowed keys
  • Loading branch information
moufmouf committed Jun 13, 2019
commit 693f88961cc0ba61d60fb65f62f6ef83e9c1f09c
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg

protected function __construct(string $namespace = '', int $defaultLifetime = 0)
{
$this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).':';
$this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).'_';
if (null !== $this->maxIdLength && \strlen($namespace) > $this->maxIdLength - 24) {
throw new InvalidArgumentException(sprintf('Namespace must be %d chars max, %d given ("%s")', $this->maxIdLength - 24, \strlen($namespace), $namespace));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function testLongKey()
$cache->expects($this->exactly(2))
->method('doHave')
->withConsecutive(
[$this->equalTo('----------:nWfzGiCgLczv3SSUzXL3kg:')],
[$this->equalTo('----------:---------------------------------------')]
[$this->equalTo('----------_nWfzGiCgLczv3SSUzXL3kg:')],
[$this->equalTo('----------_---------------------------------------')]
);

$cache->hasItem(str_repeat('-', 40));
Expand All @@ -46,7 +46,7 @@ public function testLongKeyVersioning()
$reflectionMethod->setAccessible(true);

// No versioning enabled
$this->assertEquals('--------------------------:------------', $reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)]));
$this->assertEquals('--------------------------_------------', $reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)]));
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)])));
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 23)])));
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 40)])));
Expand All @@ -56,7 +56,7 @@ public function testLongKeyVersioning()
$reflectionProperty->setValue($cache, true);

// Versioning enabled
$this->assertEquals('--------------------------:1/------------', $reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)]));
$this->assertEquals('--------------------------_1/------------', $reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)]));
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 12)])));
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 23)])));
$this->assertLessThanOrEqual(50, \strlen($reflectionMethod->invokeArgs($cache, [str_repeat('-', 40)])));
Expand Down