[Cache] Limit cache version character range

This commit is contained in:
Lars Strojny 2020-09-09 12:57:09 +02:00 committed by Nicolas Grekas
parent afd4027c11
commit 15c21db856
2 changed files with 3 additions and 3 deletions

View File

@ -182,7 +182,7 @@ abstract class AbstractCache implements Psr16CacheInterface, LoggerAwareInterfac
try {
foreach ($values as $id => $value) {
if (!isset($keys[$id])) {
$id = key($keys);
throw new InvalidArgumentException(sprintf('Could not match value id "%s" to keys "%s".', $id, implode('", "', $keys)));
}
$key = $keys[$id];
unset($keys[$id]);

View File

@ -119,7 +119,7 @@ trait AbstractTrait
}
}
$namespaceToClear = $this->namespace.$namespaceVersionToClear;
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5);
$namespaceVersion = strtr(substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5), '/', '_');
try {
$cleared = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0);
} catch (\Exception $e) {
@ -268,7 +268,7 @@ trait AbstractTrait
$this->namespaceVersion = $v;
}
if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) {
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5);
$this->namespaceVersion = strtr(substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5), '/', '_');
$this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0);
}
} catch (\Exception $e) {