From c08fd1e52fa82ea8f0f853042e327972377a8da4 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 6 Jun 2021 21:13:01 +0200 Subject: [PATCH] Remove support for Doctrine Cache --- UPGRADE.md | 11 +++ composer.json | 1 - phpstan.neon.dist | 12 --- psalm.xml.dist | 15 ---- src/Cache/QueryCacheProfile.php | 73 ++---------------- src/Configuration.php | 51 +----------- tests/Functional/ResultCacheTest.php | 111 --------------------------- 7 files changed, 20 insertions(+), 254 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 239a8615426..f6f327c3938 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -300,6 +300,17 @@ The Doctrine\DBAL\Version class is no longer available: please refrain from chec Use binary fields of a size which fits all target platforms, or use blob explicitly instead. - Binary fields are no longer represented as streams in PHP. They are represented as strings. +## BC BREAK: Removal of Doctrine Cache + +The following methods have been removed. + +| class | method | replacement | +| ------------------- | ------------------------ | ------------------ | +| `Configuration` | `setResultCacheImpl()` | `setResultCache()` | +| `Configuration` | `getResultCacheImpl()` | `getResultCache()` | +| `QueryCacheProfile` | `setResultCacheDriver()` | `setResultCache()` | +| `QueryCacheProfile` | `getResultCacheDriver()` | `getResultCache()` | + # Upgrade to 3.2 ## Introduction of PSR-6 for result caching diff --git a/composer.json b/composer.json index 1b9626767cd..9ad36545d9f 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,6 @@ "require": { "php": "^7.3 || ^8.0", "composer/package-versions-deprecated": "^1.11.99", - "doctrine/cache": "^1.11|^2.0", "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0", "psr/cache": "^1|^2|^3" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f5b5e3f9b3e..f82076114c4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -123,18 +123,6 @@ parameters: message: '~^Instanceof between Doctrine\\DBAL\\Platforms\\Keywords\\KeywordList and Doctrine\\DBAL\\Platforms\\Keywords\\KeywordList will always evaluate to true\.~' paths: - %currentWorkingDirectory%/src/Platforms/AbstractPlatform.php - - # We're checking for invalid invalid input - - - message: "#^Strict comparison using \\!\\=\\= between null and null will always evaluate to false\\.$#" - count: 1 - path: src/Cache/QueryCacheProfile.php - - # The Doctrine\Common\Cache\ArrayCache class won't exist if doctrine/cache 2 is installed - # TODO: remove by 4.0.0 - - - message: '~^Parameter #3 \$resultCache of class Doctrine\\DBAL\\Cache\\QueryCacheProfile constructor expects Doctrine\\Common\\Cache\\Cache\|Psr\\Cache\\CacheItemPoolInterface\|null, Doctrine\\Common\\Cache\\ArrayCache given\.~' - path: tests/Functional/ResultCacheTest.php includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon diff --git a/psalm.xml.dist b/psalm.xml.dist index cf9df327d45..2286ac5aa07 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -45,11 +45,6 @@ is no longer supported. --> - - @@ -66,15 +61,6 @@ - - - - - - - diff --git a/src/Cache/QueryCacheProfile.php b/src/Cache/QueryCacheProfile.php index ba393551638..be809801a94 100644 --- a/src/Cache/QueryCacheProfile.php +++ b/src/Cache/QueryCacheProfile.php @@ -4,20 +4,13 @@ namespace Doctrine\DBAL\Cache; -use Doctrine\Common\Cache\Cache; -use Doctrine\Common\Cache\Psr6\CacheAdapter; -use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Cache\Exception\NoCacheKey; use Doctrine\DBAL\Types\Type; -use Doctrine\Deprecations\Deprecation; use Psr\Cache\CacheItemPoolInterface; -use TypeError; -use function get_class; use function hash; use function serialize; use function sha1; -use function sprintf; /** * Query Cache Profile handles the data relevant for query caching. @@ -35,34 +28,14 @@ class QueryCacheProfile /** @var string|null */ private $cacheKey; - /** - * @param CacheItemPoolInterface|Cache|null $resultCache - */ - public function __construct(int $lifetime = 0, ?string $cacheKey = null, ?object $resultCache = null) - { - $this->lifetime = $lifetime; - $this->cacheKey = $cacheKey; - if ($resultCache instanceof CacheItemPoolInterface) { - $this->resultCache = $resultCache; - } elseif ($resultCache instanceof Cache) { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4620', - 'Passing an instance of %s to %s as $resultCache is deprecated. Pass an instance of %s instead.', - Cache::class, - __METHOD__, - CacheItemPoolInterface::class - ); - - $this->resultCache = CacheAdapter::wrap($resultCache); - } elseif ($resultCache !== null) { - throw new TypeError(sprintf( - '$resultCache: Expected either null or an instance of %s or %s, got %s.', - CacheItemPoolInterface::class, - Cache::class, - get_class($resultCache) - )); - } + public function __construct( + int $lifetime = 0, + ?string $cacheKey = null, + ?CacheItemPoolInterface $resultCache = null + ) { + $this->lifetime = $lifetime; + $this->cacheKey = $cacheKey; + $this->resultCache = $resultCache; } public function getResultCache(): ?CacheItemPoolInterface @@ -70,21 +43,6 @@ public function getResultCache(): ?CacheItemPoolInterface return $this->resultCache; } - /** - * @deprecated Use {@see getResultCache()} instead. - */ - public function getResultCacheDriver(): ?Cache - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4620', - '%s is deprecated, call getResultCache() instead.', - __METHOD__ - ); - - return $this->resultCache !== null ? DoctrineProvider::wrap($this->resultCache) : null; - } - public function getLifetime(): int { return $this->lifetime; @@ -133,21 +91,6 @@ public function setResultCache(CacheItemPoolInterface $cache): QueryCacheProfile return new QueryCacheProfile($this->lifetime, $this->cacheKey, $cache); } - /** - * @deprecated Use {@see setResultCache()} instead. - */ - public function setResultCacheDriver(Cache $cache): self - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4620', - '%s is deprecated, call setResultCache() instead.', - __METHOD__ - ); - - return new QueryCacheProfile($this->lifetime, $this->cacheKey, CacheAdapter::wrap($cache)); - } - public function setCacheKey(?string $cacheKey): self { return new QueryCacheProfile($this->lifetime, $cacheKey, $this->resultCache); diff --git a/src/Configuration.php b/src/Configuration.php index 328e2fcdd34..a83d55a2b0f 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -4,13 +4,9 @@ namespace Doctrine\DBAL; -use Doctrine\Common\Cache\Cache; -use Doctrine\Common\Cache\Psr6\CacheAdapter; -use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Driver\Middleware; use Doctrine\DBAL\Logging\NullLogger; use Doctrine\DBAL\Logging\SQLLogger; -use Doctrine\Deprecations\Deprecation; use Psr\Cache\CacheItemPoolInterface; /** @@ -35,15 +31,6 @@ class Configuration */ private $resultCache; - /** - * The cache driver implementation that is used for query result caching. - * - * @deprecated Use {@see $resultCache} instead. - * - * @var Cache|null - */ - protected $resultCacheImpl; - /** * The callable to use to filter schema assets. * @@ -82,48 +69,12 @@ public function getResultCache(): ?CacheItemPoolInterface return $this->resultCache; } - /** - * Gets the cache driver implementation that is used for query result caching. - * - * @deprecated Use {@see getResultCache()} instead. - */ - public function getResultCacheImpl(): ?Cache - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4620', - '%s is deprecated, call getResultCache() instead.', - __METHOD__ - ); - - return $this->resultCacheImpl; - } - /** * Sets the cache driver implementation that is used for query result caching. */ public function setResultCache(CacheItemPoolInterface $cache): void { - $this->resultCacheImpl = DoctrineProvider::wrap($cache); - $this->resultCache = $cache; - } - - /** - * Sets the cache driver implementation that is used for query result caching. - * - * @deprecated Use {@see setResultCache()} instead. - */ - public function setResultCacheImpl(Cache $cacheImpl): void - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/4620', - '%s is deprecated, call setResultCache() instead.', - __METHOD__ - ); - - $this->resultCacheImpl = $cacheImpl; - $this->resultCache = CacheAdapter::wrap($cacheImpl); + $this->resultCache = $cache; } /** diff --git a/tests/Functional/ResultCacheTest.php b/tests/Functional/ResultCacheTest.php index f05a00616cc..5da34beb3cb 100644 --- a/tests/Functional/ResultCacheTest.php +++ b/tests/Functional/ResultCacheTest.php @@ -4,8 +4,6 @@ namespace Doctrine\DBAL\Tests\Functional; -use Doctrine\Common\Cache\ArrayCache; -use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Result; @@ -16,7 +14,6 @@ use function array_change_key_case; use function array_shift; use function array_values; -use function class_exists; use function is_array; use const CASE_LOWER; @@ -228,49 +225,6 @@ public function testFetchingAllRowsSavesCache(callable $fetchAll): void self::assertCount(1, $layerCache->getItem('testcachekey')->get()); } - /** - * @dataProvider fetchAllProvider - */ - public function testFetchingAllRowsSavesCacheLegacy(callable $fetchAll): void - { - if (! class_exists(ArrayCache::class)) { - self::markTestSkipped('This test requires the legacy ArrayCache class.'); - } - - $layerCache = new ArrayCache(); - - $result = $this->connection->executeQuery( - 'SELECT * FROM caching WHERE test_int > 500', - [], - [], - new QueryCacheProfile(0, 'testcachekey', $layerCache) - ); - - $fetchAll($result); - - self::assertCount(1, $layerCache->fetch('testcachekey')); - } - - /** - * @dataProvider fetchAllProvider - */ - public function testFetchingAllRowsSavesCacheLegacyWrapped(callable $fetchAll): void - { - $arrayAdapter = new ArrayAdapter(); - $layerCache = DoctrineProvider::wrap($arrayAdapter); - - $result = $this->connection->executeQuery( - 'SELECT * FROM caching WHERE test_int > 500', - [], - [], - new QueryCacheProfile(0, 'testcachekey', $layerCache) - ); - - $fetchAll($result); - - self::assertCount(1, $arrayAdapter->getItem('testcachekey')->get()); - } - /** * @return iterable> */ @@ -396,71 +350,6 @@ public function testChangeCacheImpl(): void self::assertCount(1, $secondCache->getItem('emptycachekey')->get()); } - public function testChangeCacheImplLegacy(): void - { - if (! class_exists(ArrayCache::class)) { - self::markTestSkipped('This test requires the legacy ArrayCache class.'); - } - - $stmt = $this->connection->executeQuery( - 'SELECT * FROM caching WHERE test_int > 500', - [], - [], - new QueryCacheProfile(10, 'emptycachekey') - ); - - $this->hydrateViaIteration($stmt, static function (Result $result) { - return $result->fetchAssociative(); - }); - - $secondCache = new ArrayCache(); - - $stmt = $this->connection->executeQuery( - 'SELECT * FROM caching WHERE test_int > 500', - [], - [], - new QueryCacheProfile(10, 'emptycachekey', $secondCache) - ); - - $this->hydrateViaIteration($stmt, static function (Result $result) { - return $result->fetchAssociative(); - }); - - self::assertCount(2, $this->sqlLogger->queries, 'Two queries have hit the database.'); - self::assertCount(1, $secondCache->fetch('emptycachekey')); - } - - public function testChangeCacheImplLegacyWrapped(): void - { - $stmt = $this->connection->executeQuery( - 'SELECT * FROM caching WHERE test_int > 500', - [], - [], - new QueryCacheProfile(10, 'emptycachekey') - ); - - $this->hydrateViaIteration($stmt, static function (Result $result) { - return $result->fetchAssociative(); - }); - - $arrayAdapter = new ArrayAdapter(); - $secondCache = DoctrineProvider::wrap($arrayAdapter); - - $stmt = $this->connection->executeQuery( - 'SELECT * FROM caching WHERE test_int > 500', - [], - [], - new QueryCacheProfile(10, 'emptycachekey', $secondCache) - ); - - $this->hydrateViaIteration($stmt, static function (Result $result) { - return $result->fetchAssociative(); - }); - - self::assertCount(2, $this->sqlLogger->queries, 'Two queries have hit the database.'); - self::assertCount(1, $arrayAdapter->getItem('emptycachekey')->get()); - } - /** * @return iterable> */