Skip to content

Commit

Permalink
Merge pull request doctrine#4624 from derrabus/deprecate/doctrine-cache
Browse files Browse the repository at this point in the history
Deprecate `doctrine/cache` in favor of `psr/cache`
  • Loading branch information
greg0ire authored May 1, 2021
2 parents 37c9043 + a114b79 commit e026b54
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| ------------------- | ------------------------ | ------------------ |
Expand Down
24 changes: 24 additions & 0 deletions src/Cache/QueryCacheProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand All @@ -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;
}

Expand Down Expand Up @@ -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));
}

Expand Down
15 changes: 15 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
Expand Down

0 comments on commit e026b54

Please sign in to comment.