diff --git a/UPGRADE.md b/UPGRADE.md index 9fe6308cf8f..b2565e7add2 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -11,8 +11,9 @@ awareness about deprecated code. ## Introduction of PSR-6 for result caching Instead of relying on the deprecated `doctrine/cache` library, a PSR-6 cache -can now be used for result caching. Please use the following new methods for -this purpose: +can now be used for result caching. The usage of Doctrine Cache is deprecated +in favor of PSR-6. The following methods related to Doctrine Cache have been +replaced with PSR-6 counterparts: | class | old method | new method | | ------------------- | ------------------------ | ------------------ | diff --git a/src/Cache/QueryCacheProfile.php b/src/Cache/QueryCacheProfile.php index dd4abd62eb3..2c2ef210643 100644 --- a/src/Cache/QueryCacheProfile.php +++ b/src/Cache/QueryCacheProfile.php @@ -6,6 +6,7 @@ use Doctrine\Common\Cache\Psr6\CacheAdapter; use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use Psr\Cache\CacheItemPoolInterface; use TypeError; @@ -43,6 +44,15 @@ public function __construct($lifetime = 0, $cacheKey = null, ?object $resultCach 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( @@ -66,6 +76,13 @@ public function getResultCache(): ?CacheItemPoolInterface */ public function getResultCacheDriver() { + 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; } @@ -130,6 +147,13 @@ public function setResultCache(CacheItemPoolInterface $cache): QueryCacheProfile */ public function setResultCacheDriver(Cache $cache) { + 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)); } diff --git a/src/Configuration.php b/src/Configuration.php index 44f7233a23c..2d27d733b86 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -7,6 +7,7 @@ use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Driver\Middleware; use Doctrine\DBAL\Logging\SQLLogger; +use Doctrine\Deprecations\Deprecation; use Psr\Cache\CacheItemPoolInterface; /** @@ -85,6 +86,13 @@ public function getResultCache(): ?CacheItemPoolInterface */ 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; } @@ -104,6 +112,13 @@ public function setResultCache(CacheItemPoolInterface $cache): void */ 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); }