[Cache] Rename nonce to version
This commit is contained in:
parent
7a4019bbcf
commit
0c8358b3fe
@ -1037,9 +1037,9 @@ class FrameworkExtension extends Extension
|
||||
|
||||
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||
{
|
||||
$nonce = substr(str_replace('/', '-', base64_encode(md5(uniqid(mt_rand(), true), true))), 0, -2);
|
||||
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $nonce);
|
||||
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $nonce);
|
||||
$version = substr(str_replace('/', '-', base64_encode(md5(uniqid(mt_rand(), true), true))), 0, -2);
|
||||
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
|
||||
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
|
||||
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);
|
||||
|
||||
foreach (array('doctrine', 'psr6', 'redis') as $name) {
|
||||
|
@ -28,7 +28,7 @@
|
||||
<tag name="monolog.logger" channel="cache" />
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
<argument /> <!-- nonce -->
|
||||
<argument /> <!-- version -->
|
||||
<argument>%kernel.cache_dir%/pools</argument>
|
||||
<argument type="service" id="logger" on-invalid="ignore" />
|
||||
</service>
|
||||
@ -38,7 +38,7 @@
|
||||
<tag name="monolog.logger" channel="cache" />
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
<argument /> <!-- nonce -->
|
||||
<argument /> <!-- version -->
|
||||
<call method="setLogger">
|
||||
<argument type="service" id="logger" on-invalid="ignore" />
|
||||
</call>
|
||||
|
@ -68,7 +68,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
|
||||
);
|
||||
}
|
||||
|
||||
public static function createSystemCache($namespace, $defaultLifetime, $nonce, $directory, LoggerInterface $logger = null)
|
||||
public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
|
||||
{
|
||||
$fs = new FilesystemAdapter($namespace, $defaultLifetime, $directory);
|
||||
if (null !== $logger) {
|
||||
@ -78,7 +78,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
|
||||
return $fs;
|
||||
}
|
||||
|
||||
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $nonce);
|
||||
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $version);
|
||||
if (null !== $logger) {
|
||||
$apcu->setLogger($logger);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class ApcuAdapter extends AbstractAdapter
|
||||
return function_exists('apcu_fetch') && ini_get('apc.enabled') && !('cli' === PHP_SAPI && !ini_get('apc.enable_cli'));
|
||||
}
|
||||
|
||||
public function __construct($namespace = '', $defaultLifetime = 0, $nonce = null)
|
||||
public function __construct($namespace = '', $defaultLifetime = 0, $version = null)
|
||||
{
|
||||
if (!static::isSupported()) {
|
||||
throw new CacheException('APCu is not enabled');
|
||||
@ -34,12 +34,12 @@ class ApcuAdapter extends AbstractAdapter
|
||||
}
|
||||
parent::__construct($namespace, $defaultLifetime);
|
||||
|
||||
if (null !== $nonce) {
|
||||
CacheItem::validateKey($nonce);
|
||||
if (null !== $version) {
|
||||
CacheItem::validateKey($version);
|
||||
|
||||
if (!apcu_exists($nonce.':nonce'.$namespace)) {
|
||||
if (!apcu_exists($version.':'.$namespace)) {
|
||||
$this->clear($namespace);
|
||||
apcu_add($nonce.':nonce'.$namespace, null);
|
||||
apcu_add($version.':'.$namespace, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class ApcuAdapterTest extends CachePoolTest
|
||||
$this->assertFalse($item->isHit());
|
||||
}
|
||||
|
||||
public function testNonce()
|
||||
public function testVersion()
|
||||
{
|
||||
$namespace = str_replace('\\', '.', __CLASS__);
|
||||
|
||||
|
Reference in New Issue
Block a user