bug #40273 [Cache] fix setting items' metadata on commit() (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[Cache] fix setting items' metadata on commit()

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36697
| License       | MIT
| Doc PR        | -

Commits
-------

9bb4b3106d [Cache] fix setting items' metadata on commit()
This commit is contained in:
Nicolas Grekas 2021-02-22 15:52:02 +01:00
commit 0027d1cd05
15 changed files with 8 additions and 13 deletions

View File

@ -110,6 +110,7 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
} }
$byLifetime[$ttl][$getId($key)] = $value; $byLifetime[$ttl][$getId($key)] = $value;
$item->metadata = $item->newMetadata;
} }
return $byLifetime; return $byLifetime;

View File

@ -83,6 +83,7 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac
$tagsByKey = []; $tagsByKey = [];
foreach ($deferred as $key => $item) { foreach ($deferred as $key => $item) {
$tagsByKey[$key] = $item->newMetadata[CacheItem::METADATA_TAGS] ?? []; $tagsByKey[$key] = $item->newMetadata[CacheItem::METADATA_TAGS] ?? [];
$item->metadata = $item->newMetadata;
} }
return $tagsByKey; return $tagsByKey;

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter; use Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/** /**
* @group time-sensitive * @group time-sensitive

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\PdoAdapter; use Symfony\Component\Cache\Adapter\PdoAdapter;
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
/** /**
* @group time-sensitive * @group time-sensitive

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\PdoAdapter; use Symfony\Component\Cache\Adapter\PdoAdapter;
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
/** /**
* @group time-sensitive * @group time-sensitive

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\Cache\Tests\Traits; namespace Symfony\Component\Cache\Tests\Adapter;
trait PdoPruneableTrait trait PdoPruneableTrait
{ {

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter; use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/** /**
* @group integration * @group integration

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter; use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/** /**
* @group integration * @group integration

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter; use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
use Symfony\Component\Cache\Traits\RedisProxy; use Symfony\Component\Cache\Traits\RedisProxy;
/** /**

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter; use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/** /**
* @group integration * @group integration

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter; use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
use Symfony\Component\Cache\Traits\RedisClusterProxy; use Symfony\Component\Cache\Traits\RedisClusterProxy;
/** /**

View File

@ -19,7 +19,6 @@ use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter; use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Tests\Fixtures\PrunableAdapter; use Symfony\Component\Cache\Tests\Fixtures\PrunableAdapter;
use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait;
/** /**
* @group time-sensitive * @group time-sensitive

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Symfony\Component\Cache\Tests\Traits; namespace Symfony\Component\Cache\Tests\Adapter;
use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\CacheItem;
@ -150,7 +150,9 @@ trait TagAwareTestTrait
$pool = $this->createCachePool(); $pool = $this->createCachePool();
$i = $pool->getItem('k'); $i = $pool->getItem('k');
$this->assertSame([], $i->getMetadata());
$pool->save($i->tag('foo')); $pool->save($i->tag('foo'));
$this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]);
$i = $pool->getItem('k'); $i = $pool->getItem('k');
$this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]); $this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]);

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Cache\Tests\Simple;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Cache\Simple\PdoCache; use Symfony\Component\Cache\Simple\PdoCache;
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait; use Symfony\Component\Cache\Tests\Adapter\PdoPruneableTrait;
/** /**
* @group time-sensitive * @group time-sensitive

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Cache\Tests\Simple;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Cache\Simple\PdoCache; use Symfony\Component\Cache\Simple\PdoCache;
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait; use Symfony\Component\Cache\Tests\Adapter\PdoPruneableTrait;
/** /**
* @group time-sensitive * @group time-sensitive