Skip to content

Commit 2bf5da5

Browse files
[Cache] replace getNsSeparator by NS_SEPARATOR on AbstractTrait
1 parent 02a6f24 commit 2bf5da5

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
*/
2626
abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface, ResettableInterface
2727
{
28+
/**
29+
* @internal
30+
*/
31+
const NS_SEPARATOR = ':';
32+
2833
use AbstractTrait;
2934

3035
private static $apcuSupported;
@@ -39,7 +44,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
3944
*/
4045
protected function __construct($namespace = '', $defaultLifetime = 0)
4146
{
42-
$this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).static::getNsSeparator();
47+
$this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).static::NS_SEPARATOR;
4348
if (null !== $this->maxIdLength && \strlen($namespace) > $this->maxIdLength - 24) {
4449
throw new InvalidArgumentException(sprintf('Namespace must be %d chars max, %d given ("%s")', $this->maxIdLength - 24, \strlen($namespace), $namespace));
4550
}

src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
*/
2121
class SimpleCacheAdapter extends AbstractAdapter implements PruneableInterface
2222
{
23+
/**
24+
* @internal
25+
*/
26+
const NS_SEPARATOR = '_';
27+
2328
use ProxyTrait;
2429

2530
private $miss;
@@ -75,14 +80,4 @@ protected function doSave(array $values, $lifetime)
7580
{
7681
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
7782
}
78-
79-
/**
80-
* @return string the namespace separator for cache keys
81-
*
82-
* @internal
83-
*/
84-
protected static function getNsSeparator()
85-
{
86-
return '_';
87-
}
8883
}

src/Symfony/Component/Cache/Simple/AbstractCache.php

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
*/
2424
abstract class AbstractCache implements CacheInterface, LoggerAwareInterface, ResettableInterface
2525
{
26+
/**
27+
* @internal
28+
*/
29+
const NS_SEPARATOR = ':';
30+
2631
use AbstractTrait {
2732
deleteItems as private;
2833
AbstractTrait::deleteItem as delete;

src/Symfony/Component/Cache/Traits/AbstractTrait.php

+8-18
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ public function clear()
106106
{
107107
$this->deferred = [];
108108
if ($cleared = $this->versioningIsEnabled) {
109-
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::getNsSeparator(), 5);
109+
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5);
110110
try {
111-
$cleared = $this->doSave([static::getNsSeparator().$this->namespace => $namespaceVersion], 0);
111+
$cleared = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0);
112112
} catch (\Exception $e) {
113113
$cleared = false;
114114
}
@@ -235,14 +235,14 @@ private function getId($key)
235235
CacheItem::validateKey($key);
236236

237237
if ($this->versioningIsEnabled && '' === $this->namespaceVersion) {
238-
$this->namespaceVersion = '1'.static::getNsSeparator();
238+
$this->namespaceVersion = '1'.static::NS_SEPARATOR;
239239
try {
240-
foreach ($this->doFetch([static::getNsSeparator().$this->namespace]) as $v) {
240+
foreach ($this->doFetch([static::NS_SEPARATOR.$this->namespace]) as $v) {
241241
$this->namespaceVersion = $v;
242242
}
243-
if ('1'.static::getNsSeparator() === $this->namespaceVersion) {
244-
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::getNsSeparator(), 5);
245-
$this->doSave([static::getNsSeparator().$this->namespace => $this->namespaceVersion], 0);
243+
if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) {
244+
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5);
245+
$this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0);
246246
}
247247
} catch (\Exception $e) {
248248
}
@@ -252,7 +252,7 @@ private function getId($key)
252252
return $this->namespace.$this->namespaceVersion.$key;
253253
}
254254
if (\strlen($id = $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) {
255-
$id = $this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256', $key, true)), static::getNsSeparator(), -(\strlen($this->namespaceVersion) + 22));
255+
$id = $this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256', $key, true)), static::NS_SEPARATOR, -(\strlen($this->namespaceVersion) + 22));
256256
}
257257

258258
return $id;
@@ -265,14 +265,4 @@ public static function handleUnserializeCallback($class)
265265
{
266266
throw new \DomainException('Class not found: '.$class);
267267
}
268-
269-
/**
270-
* @return string the namespace separator for cache keys
271-
*
272-
* @internal
273-
*/
274-
protected static function getNsSeparator()
275-
{
276-
return ':';
277-
}
278268
}

0 commit comments

Comments
 (0)