Skip to content

Commit 1af202b

Browse files
authored
Remove support for Doctrine Cache in second level cache (#9348)
1 parent 98331a6 commit 1af202b

File tree

10 files changed

+35
-252
lines changed

10 files changed

+35
-252
lines changed

UPGRADE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: PSR-6-based second level cache
4+
5+
The second level cache has been reworked to consume a PSR-6 cache. Using a
6+
Doctrine Cache instance is not supported anymore.
7+
8+
* `DefaultCacheFactory`: The constructor expects a PSR-6 cache item pool as
9+
second argument now.
10+
* `DefaultMultiGetRegion`: This class has been removed.
11+
* `DefaultRegion`:
12+
* The constructor expects a PSR-6 cache item pool as second argument now.
13+
* The protected `$cache` property is removed.
14+
* The properties `$name` and `$lifetime` as well as the constant
15+
`REGION_KEY_SEPARATOR` and the method `getCacheEntryKey()` are
16+
`private` now.
17+
* The method `getCache()` has been removed.
18+
19+
320
## BC Break: Remove `Doctrine\ORM\Mapping\Driver\PHPDriver`
421

522
Use `StaticPHPDriver` instead when you want to programmatically configure

lib/Doctrine/ORM/Cache/DefaultCacheFactory.php

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace Doctrine\ORM\Cache;
66

7-
use Doctrine\Common\Cache\Cache as LegacyCache;
8-
use Doctrine\Common\Cache\Psr6\CacheAdapter;
9-
use Doctrine\Deprecations\Deprecation;
107
use Doctrine\ORM\Cache;
118
use Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister;
129
use Doctrine\ORM\Cache\Persister\Collection\ReadOnlyCachedCollectionPersister;
@@ -24,58 +21,26 @@
2421
use InvalidArgumentException;
2522
use LogicException;
2623
use Psr\Cache\CacheItemPoolInterface;
27-
use TypeError;
2824

2925
use function assert;
30-
use function get_debug_type;
3126
use function sprintf;
3227

3328
use const DIRECTORY_SEPARATOR;
3429

3530
class DefaultCacheFactory implements CacheFactory
3631
{
37-
/** @var CacheItemPoolInterface */
38-
private $cacheItemPool;
39-
40-
/** @var RegionsConfiguration */
41-
private $regionsConfig;
42-
43-
/** @var TimestampRegion|null */
44-
private $timestampRegion;
32+
private CacheItemPoolInterface $cacheItemPool;
33+
private RegionsConfiguration $regionsConfig;
34+
private ?TimestampRegion $timestampRegion = null;
4535

4636
/** @var Region[] */
47-
private $regions = [];
37+
private array $regions = [];
4838

49-
/** @var string|null */
50-
private $fileLockRegionDirectory;
39+
private ?string $fileLockRegionDirectory = null;
5140

52-
/**
53-
* @param CacheItemPoolInterface $cacheItemPool
54-
*/
55-
public function __construct(RegionsConfiguration $cacheConfig, $cacheItemPool)
41+
public function __construct(RegionsConfiguration $cacheConfig, CacheItemPoolInterface $cacheItemPool)
5642
{
57-
if ($cacheItemPool instanceof LegacyCache) {
58-
Deprecation::trigger(
59-
'doctrine/orm',
60-
'https://github.com/doctrine/orm/pull/9322',
61-
'Passing an instance of %s to %s is deprecated, pass a %s instead.',
62-
get_debug_type($cacheItemPool),
63-
__METHOD__,
64-
CacheItemPoolInterface::class
65-
);
66-
67-
$this->cacheItemPool = CacheAdapter::wrap($cacheItemPool);
68-
} elseif (! $cacheItemPool instanceof CacheItemPoolInterface) {
69-
throw new TypeError(sprintf(
70-
'%s: Parameter #2 is expected to be an instance of %s, got %s.',
71-
__METHOD__,
72-
CacheItemPoolInterface::class,
73-
get_debug_type($cacheItemPool)
74-
));
75-
} else {
76-
$this->cacheItemPool = $cacheItemPool;
77-
}
78-
43+
$this->cacheItemPool = $cacheItemPool;
7944
$this->regionsConfig = $cacheConfig;
8045
}
8146

lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/Doctrine/ORM/Cache/Region/DefaultRegion.php

Lines changed: 10 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
namespace Doctrine\ORM\Cache\Region;
66

77
use Closure;
8-
use Doctrine\Common\Cache\Cache as LegacyCache;
9-
use Doctrine\Common\Cache\CacheProvider;
10-
use Doctrine\Common\Cache\Psr6\CacheAdapter;
11-
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
12-
use Doctrine\Deprecations\Deprecation;
138
use Doctrine\ORM\Cache\CacheEntry;
149
use Doctrine\ORM\Cache\CacheKey;
1510
use Doctrine\ORM\Cache\CollectionCacheEntry;
@@ -18,80 +13,28 @@
1813
use Psr\Cache\CacheItemInterface;
1914
use Psr\Cache\CacheItemPoolInterface;
2015
use Traversable;
21-
use TypeError;
2216

2317
use function array_map;
24-
use function get_debug_type;
2518
use function iterator_to_array;
26-
use function sprintf;
2719
use function strtr;
2820

2921
/**
3022
* The simplest cache region compatible with all doctrine-cache drivers.
3123
*/
3224
class DefaultRegion implements Region
3325
{
34-
/**
35-
* @internal since 2.11, this constant will be private in 3.0.
36-
*/
37-
public const REGION_KEY_SEPARATOR = '_';
38-
private const REGION_PREFIX = 'DC2_REGION_';
39-
40-
/**
41-
* @deprecated since 2.11, this property will be removed in 3.0.
42-
*
43-
* @var LegacyCache
44-
*/
45-
protected $cache;
46-
47-
/**
48-
* @internal since 2.11, this property will be private in 3.0.
49-
*
50-
* @var string
51-
*/
52-
protected $name;
53-
54-
/**
55-
* @internal since 2.11, this property will be private in 3.0.
56-
*
57-
* @var int
58-
*/
59-
protected $lifetime = 0;
26+
private const REGION_KEY_SEPARATOR = '_';
27+
private const REGION_PREFIX = 'DC2_REGION_';
6028

61-
/** @var CacheItemPoolInterface */
62-
private $cacheItemPool;
29+
private string $name;
30+
private int $lifetime = 0;
31+
private CacheItemPoolInterface $cacheItemPool;
6332

64-
/**
65-
* @param CacheItemPoolInterface $cacheItemPool
66-
*/
67-
public function __construct(string $name, $cacheItemPool, int $lifetime = 0)
33+
public function __construct(string $name, CacheItemPoolInterface $cacheItemPool, int $lifetime = 0)
6834
{
69-
if ($cacheItemPool instanceof LegacyCache) {
70-
Deprecation::trigger(
71-
'doctrine/orm',
72-
'https://github.com/doctrine/orm/pull/9322',
73-
'Passing an instance of %s to %s is deprecated, pass a %s instead.',
74-
get_debug_type($cacheItemPool),
75-
__METHOD__,
76-
CacheItemPoolInterface::class
77-
);
78-
79-
$this->cache = $cacheItemPool;
80-
$this->cacheItemPool = CacheAdapter::wrap($cacheItemPool);
81-
} elseif (! $cacheItemPool instanceof CacheItemPoolInterface) {
82-
throw new TypeError(sprintf(
83-
'%s: Parameter #2 is expected to be an instance of %s, got %s.',
84-
__METHOD__,
85-
CacheItemPoolInterface::class,
86-
get_debug_type($cacheItemPool)
87-
));
88-
} else {
89-
$this->cache = DoctrineProvider::wrap($cacheItemPool);
90-
$this->cacheItemPool = $cacheItemPool;
91-
}
92-
93-
$this->name = $name;
94-
$this->lifetime = $lifetime;
35+
$this->cacheItemPool = $cacheItemPool;
36+
$this->name = $name;
37+
$this->lifetime = $lifetime;
9538
}
9639

9740
/**
@@ -102,16 +45,6 @@ public function getName()
10245
return $this->name;
10346
}
10447

105-
/**
106-
* @deprecated
107-
*
108-
* @return CacheProvider
109-
*/
110-
public function getCache()
111-
{
112-
return $this->cache;
113-
}
114-
11548
/**
11649
* {@inheritdoc}
11750
*/
@@ -205,12 +138,7 @@ public function evictAll()
205138
return $this->cacheItemPool->clear(self::REGION_PREFIX . $this->name);
206139
}
207140

208-
/**
209-
* @internal since 2.11, this method will be private in 3.0.
210-
*
211-
* @return string
212-
*/
213-
protected function getCacheEntryKey(CacheKey $key)
141+
private function getCacheEntryKey(CacheKey $key): string
214142
{
215143
return self::REGION_PREFIX . $this->name . self::REGION_KEY_SEPARATOR . strtr($key->hash, '{}()/\@:', '________');
216144
}

phpstan-baseline.neon

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ parameters:
9595
count: 1
9696
path: lib/Doctrine/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersister.php
9797

98-
-
99-
message: "#^Method Doctrine\\\\ORM\\\\Cache\\\\Region\\\\DefaultRegion\\:\\:getCache\\(\\) should return Doctrine\\\\Common\\\\Cache\\\\CacheProvider but returns Doctrine\\\\Common\\\\Cache\\\\Cache\\.$#"
100-
count: 1
101-
path: lib/Doctrine/ORM/Cache/Region/DefaultRegion.php
102-
10398
-
10499
message: "#^Access to an undefined property Doctrine\\\\ORM\\\\Cache\\\\CacheEntry\\:\\:\\$time\\.$#"
105100
count: 1
@@ -1569,3 +1564,4 @@ parameters:
15691564
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$subClasses\\.$#"
15701565
count: 1
15711566
path: lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php
1567+

psalm-baseline.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,6 @@
275275
<code>lock</code>
276276
</UndefinedInterfaceMethod>
277277
</file>
278-
<file src="lib/Doctrine/ORM/Cache/Region/DefaultRegion.php">
279-
<LessSpecificReturnStatement occurrences="1">
280-
<code>$this-&gt;cache</code>
281-
</LessSpecificReturnStatement>
282-
<MoreSpecificReturnType occurrences="1">
283-
<code>CacheProvider</code>
284-
</MoreSpecificReturnType>
285-
</file>
286278
<file src="lib/Doctrine/ORM/Cache/Region/UpdateTimestampCache.php">
287279
<MissingReturnType occurrences="1">
288280
<code>update</code>

psalm.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
<referencedMethod name="Doctrine\ORM\Configuration::ensureProductionSettings"/>
3232
</errorLevel>
3333
</DeprecatedMethod>
34-
<DeprecatedProperty>
35-
<errorLevel type="suppress">
36-
<referencedProperty name="Doctrine\ORM\Cache\Region\DefaultRegion::$cache"/>
37-
</errorLevel>
38-
</DeprecatedProperty>
3934
<DocblockTypeContradiction>
4035
<errorLevel type="suppress">
4136
<!-- We're catching invalid input here. -->

tests/Doctrine/Tests/ORM/Cache/DefaultRegionLegacyTest.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
namespace Doctrine\Tests\ORM\Cache;
66

7-
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
87
use Doctrine\ORM\Cache\CollectionCacheEntry;
98
use Doctrine\ORM\Cache\Region;
109
use Doctrine\ORM\Cache\Region\DefaultRegion;
1110
use Doctrine\Tests\Mocks\CacheEntryMock;
1211
use Doctrine\Tests\Mocks\CacheKeyMock;
13-
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1412

1513
use function array_map;
1614

@@ -27,7 +25,6 @@ protected function createRegion(): Region
2725
public function testGetters(): void
2826
{
2927
self::assertEquals('default.region.test', $this->region->getName());
30-
self::assertSame($this->cacheItemPool, $this->region->getCache()->getPool());
3128
}
3229

3330
public function testSharedRegion(): void
@@ -52,18 +49,6 @@ public function testSharedRegion(): void
5249
self::assertTrue($region2->contains($key));
5350
}
5451

55-
public function testDoesNotModifyCacheNamespace(): void
56-
{
57-
$cache = DoctrineProvider::wrap(new ArrayAdapter());
58-
59-
$cache->setNamespace('foo');
60-
61-
new DefaultRegion('bar', $cache);
62-
new DefaultRegion('baz', $cache);
63-
64-
self::assertSame('foo', $cache->getNamespace());
65-
}
66-
6752
public function testGetMulti(): void
6853
{
6954
$key1 = new CacheKeyMock('key.1');

0 commit comments

Comments
 (0)