diff --git a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php index 7523ab85f1..51b2bbd6c5 100644 --- a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php @@ -27,6 +27,11 @@ use Symfony\Contracts\Cache\CacheInterface; */ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface { + /** + * @internal + */ + protected const NS_SEPARATOR = ':'; + use AbstractTrait; use ContractsTrait; @@ -38,7 +43,7 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg protected function __construct(string $namespace = '', int $defaultLifetime = 0) { - $this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).static::getNsSeparator(); + $this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).static::NS_SEPARATOR; 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)); } diff --git a/src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php b/src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php index 8dbf31ff20..cc48e531c6 100644 --- a/src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php @@ -20,6 +20,11 @@ use Symfony\Component\Cache\Traits\ProxyTrait; */ class SimpleCacheAdapter extends AbstractAdapter implements PruneableInterface { + /** + * @internal + */ + protected const NS_SEPARATOR = '_'; + use ProxyTrait; private $miss; @@ -75,12 +80,4 @@ class SimpleCacheAdapter extends AbstractAdapter implements PruneableInterface { return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime); } - - /** - * @return string the namespace separator for cache keys - */ - protected static function getNsSeparator() - { - return '_'; - } } diff --git a/src/Symfony/Component/Cache/Simple/AbstractCache.php b/src/Symfony/Component/Cache/Simple/AbstractCache.php index 7a2a3cb36e..cb9e44c859 100644 --- a/src/Symfony/Component/Cache/Simple/AbstractCache.php +++ b/src/Symfony/Component/Cache/Simple/AbstractCache.php @@ -23,6 +23,11 @@ use Symfony\Component\Cache\Traits\AbstractTrait; */ abstract class AbstractCache implements CacheInterface, LoggerAwareInterface, ResettableInterface { + /** + * @internal + */ + protected const NS_SEPARATOR = ':'; + use AbstractTrait { deleteItems as private; AbstractTrait::deleteItem as delete; diff --git a/src/Symfony/Component/Cache/Traits/AbstractTrait.php b/src/Symfony/Component/Cache/Traits/AbstractTrait.php index 4fe5b9bf1a..f92e541d35 100644 --- a/src/Symfony/Component/Cache/Traits/AbstractTrait.php +++ b/src/Symfony/Component/Cache/Traits/AbstractTrait.php @@ -107,9 +107,9 @@ trait AbstractTrait { $this->deferred = []; if ($cleared = $this->versioningIsEnabled) { - $namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::getNsSeparator(), 5); + $namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5); try { - $cleared = $this->doSave([static::getNsSeparator().$this->namespace => $namespaceVersion], 0); + $cleared = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0); } catch (\Exception $e) { $cleared = false; } @@ -242,14 +242,14 @@ trait AbstractTrait { if ($this->versioningIsEnabled && '' === $this->namespaceVersion) { $this->ids = []; - $this->namespaceVersion = '1'.static::getNsSeparator(); + $this->namespaceVersion = '1'.static::NS_SEPARATOR; try { - foreach ($this->doFetch([static::getNsSeparator().$this->namespace]) as $v) { + foreach ($this->doFetch([static::NS_SEPARATOR.$this->namespace]) as $v) { $this->namespaceVersion = $v; } - if ('1'.static::getNsSeparator() === $this->namespaceVersion) { - $this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::getNsSeparator(), 5); - $this->doSave([static::getNsSeparator().$this->namespace => $this->namespaceVersion], 0); + if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) { + $this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5); + $this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0); } } catch (\Exception $e) { } @@ -266,7 +266,7 @@ trait AbstractTrait } if (\strlen($id = $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) { // Use MD5 to favor speed over security, which is not an issue here - $this->ids[$key] = $id = substr_replace(base64_encode(hash('md5', $key, true)), static::getNsSeparator(), -(\strlen($this->namespaceVersion) + 2)); + $this->ids[$key] = $id = substr_replace(base64_encode(hash('md5', $key, true)), static::NS_SEPARATOR, -(\strlen($this->namespaceVersion) + 2)); $id = $this->namespace.$this->namespaceVersion.$id; } @@ -280,12 +280,4 @@ trait AbstractTrait { throw new \DomainException('Class not found: '.$class); } - - /** - * @return string the namespace separator for cache keys - */ - protected static function getNsSeparator() - { - return ':'; - } }